Reputation: 317
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.
Upvotes: 3
Views: 406
Reputation: 10704
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)
})
Upvotes: 1