Reputation: 382
I am very new to web development. I am trying to get a page to scroll left if the mousewheel goes up, and scroll right if the mousewheel goes down. Here is my code, and any help would be greatly appreciated.
$(window).bind('mousewheel', function(e){
if(e.originalEvent.wheelDelta > 0)
{
$("*").scrollLeft(300);
}
else
{
$("*").scrollRight(300);
}
});
I'm not sure why it's breaking, anyone have some insight?
Upvotes: 1
Views: 2826
Reputation: 4383
It's because that's not the point of the .scrollLeft() function. When you do:
$("*").scrollLeft(300);
you are saying: take every element and set THEIR scrollbar to 300 on the left. In your fiddle, no element has a scrollbar, so nothing happens. If you want to use that function for this goal, you need a container div with overflow-x: scroll
. Take a look at this fiddle for a simple (and not perfect) example.
An even simpler solution for you would be to change the scrollLeft() value for the window:
$(window).scrollLeft($(window).scrollLeft()+300);
as in this other fiddle.
Upvotes: 2