Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollTop button doesn't animate

I'm probably missing something really obvious here. I've basically created a 'back to top' button that animates to the top of the page when clicked. The script doesn't seem to be pairing up with the jQuery i've written:

        <a href="#" class="back-top-top">Back to top</a>

        <script type="text/javascript">

            $(document).ready(function(event){
                $('.back-to-top').click(function(){
                    event.preventDefault();
                    $('body').animate({"scrollTop": "0px"}, 600)
                })
            })

        </script>

Other jquery elements are working fine on the site. Currently when the button is pressed the screen scrolls to the top of the page instantly which means the preventDefault isn't working, the animation time of 600ms isn't working or both.

Like I said it might be something really obvious but any help would be appreciated.

like image 565
Aero Avatar asked Aug 04 '26 22:08

Aero


1 Answers

event parameter should of onclick function of back to top button

http://jsfiddle.net/hellosze/MMgXu/ check this link

try

$('.back-to-top').click(function(event){
                    event.preventDefault();
                    $('body').animate({"scrollTop": "0px"}, 600)
                })
like image 90
Nitin Varpe Avatar answered Aug 06 '26 11:08

Nitin Varpe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!