Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot use 'in' operator to search for 'scrollLeft' in undefined

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

like image 605
AKG Avatar asked Jun 19 '13 06:06

AKG


1 Answers

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.

like image 79
adeneo Avatar answered Oct 25 '22 07:10

adeneo