AKG
AKG

Reputation: 3286

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

Upvotes: 11

Views: 12830

Answers (1)

adeneo
adeneo

Reputation: 318252

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.

Upvotes: 19

Related Questions