According to the jQuery API Documentation and some examples found here, scrollLeft is a valid argument for animate()
. However, I keep getting this error Uncaught TypeError: Cannot use 'in' operator to search for 'scrollLeft' in undefined
.
$('#prev a, #next a').click(function() {
$(window).animate({scrollLeft: 500}, 1000);
});
Is there something simple and silly that I am overlooking? What am I doing wrong? Thanks :)
The window doesn't have a scrollbar, it belongs to the body or the documentElement (html tag) :
$('#prev a, #next a').click(function() {
$('body, html').animate({scrollLeft: 500}, 1000);
});
Strange as it may seem you can get the windows scrollLeft property with css()
, but when animating, you animate the body and html tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With