Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate scroll event using Javascript

I am trying to Simulate a scroll event using Javascript for Mobile Safari. I am using the following code

var evt = document.createEvent("MouseEvents");    
evt.initMouseEvent("scroll", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);

The above code is part of a jQuery plugin jQuery.UI.Ipad which basically maps touch events like touchstart, touchmove, touchend to mouse events like mouseover, mousedown, etc

However for some reasons the code for simulating a scroll event is not working... Please help me. So essentially my question is how do I simulate the scroll event.

like image 669
copenndthagen Avatar asked Jul 20 '11 12:07

copenndthagen


1 Answers

I think people are confused as to why you would overide the scroll control. I can see why you want to imitate mouse events, but scroll maybe should not be one of them.

Usually for scroll changes you can just get the scroll with:

var top = document.body.scrollTop;

And set with:

document.body.scrollLeft = sX;
document.body.scrollTop = sY;
like image 73
MrHayman Avatar answered Oct 09 '22 18:10

MrHayman