Reputation:
I've noticed that this doesn't seem to work in Chrome. I found a fix online (that works in the demo) but I can't get it to work for some reason:
Here is the code I have:
$('#button-top').bind('click', function(e) {
try {
e.preventDefault();
target = this.hash;
$('html, body').scrollTo(target, 150);
} catch (error) {
alert('error - ' + error);
}
});
If it helps, here is a link to the site I'm building (see the link in the bottom right corner of the page):
http://www.mattpealing.co.uk/_dev/
Upvotes: 1
Views: 2589
Reputation: 4738
You are loading an old version (1.4.2) of jquery.scrollTo
. Change to the latest version 1.4.13 and it works, see the fiddle in the comments.
Upvotes: 2
Reputation: 1454
JQuery doesn't have any scrollTo()
function. However, it does have a scrollTop(position)
function.
This would work (i'm not sure what you meant with your 150):
$('#button-top').bind('click', function(e) {
try {
e.preventDefault();
target = this.hash;
$('html, body').scrollTop(150);
} catch (error) {
alert('error - ' + error);
}
});
If it's an animation you want, this will do the job (with an animation speed of 150ms):
$('#button-top').bind('click', function(e) {
try {
e.preventDefault();
target = this.hash;
$('html, body').animate({
scrollTop: 0
}, 150);
} catch (error) {
alert('error - ' + error);
}
});
Upvotes: 0