Is there a way to trigger a scroll wheel event with an arbitrary delta. Just like jQuery does with 'click' like:
$('#selector').trigger('click');
I need something like that just with an scrollwheel like:
$('#selector').trigger('DOMMouseScroll',{delta: -650});
//or mousewheel for other browsers
I can't do anything like 'fake it' with css trickery, I need to trigger the actual native (or as close as possible) event.
Thankyou!
I used this code in making my own scroll.
I added
* -1
to invert. you can remove it.Hi you can do that by adding a event listener. I have searched for the same and got the below code snippet and it is working. check you have the same requirement
based on the delta variable you can write your own custom functionality.
In html 5 mouse scroll event is being handled you can try in that way also
You can try typing this into the console, and see its effects:
where 200 is an arbitrary number. Similarly, you can also try this with scrollLeft:
or
You could try playing with this concept and the window setInterval() method.
Additionally........
You can get the offset of an element as follows:
which will give you a result like:
You could scroll to that element with something like this:
Alternatively........
If you just want the site to already be scrolled down to a particular element when the site is first loaded, you can do this with elements that have an id:
Add #idnamehere to the end of a url you are seaching. There must be an element with that id name on the page.
For example compare these URL's, and what you get when you enter them in the URL address bar:
https://travel.usnews.com/rankings/worlds-best-vacations https://travel.usnews.com/rankings/worlds-best-vacations/#vote-to-add-section
The one with #vote-to-add-section at the end is automatically scrolled down to the element with id #vote-to-add-section.
Try:
.trigger("mousewheel", {wheelDelta: 100})
(Completely untested. Inspired by Binding to the scroll wheel when over a div)
actually this works better:
This will call the scroll function if you have written any