简体   繁体   中英

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.

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)
                })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM