触发“虚拟”鼠标滚轮事件
有没有办法用任意增量触发滚轮事件?
就像 jQuery 对“点击”所做的那样:
$('#selector').trigger('click');
我需要类似的东西,只是用一个滚轮:
$('#selector').trigger('DOMMouseScroll',{delta: -650});
//or mousewheel for other browsers
我不能用 CSS 欺骗做“假它”之类的事情,我需要触发实际的本机(或尽可能接近)事件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
检查下面的代码以触发向下滚动
参考:https://developer.mozilla.org/en-US/文档/Web/API/WheelEvent
Check this below code to trigger a scrolldown
Reference: https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent
如果您编写了任何内容,这将调用滚动函数
This will call the scroll function if you have written any
您需要使用 jQuery.Event
例如:
在此处查看更多信息: http://api.jquery.com/category/events /事件对象/
You need to use jQuery.Event
For example:
Check more here: http://api.jquery.com/category/events/event-object/
您可以使用 jquery 滚动事件,并在回调时进行数学计算。请找到有用的代码片段。
You can use the jquery scroll event and on call back u can do ur math. Please find the code snipet usefull.
我用这段代码制作了我自己的卷轴。
我添加了
* -1
来反转。你可以删除它。I used this code in making my own scroll.
I added
* -1
to invert. you can remove it.您可以尝试在控制台中输入此内容,并查看其效果:
其中 200 是任意数字。
同样,您也可以尝试使用scrollLeft:
或者
您可以尝试使用这个概念和窗口setInterval()方法。
此外......
您可以按如下方式获取元素的偏移量:
这将为您提供如下结果:
您可以使用如下所示滚动到该元素:
或者........
如果您只想在首次加载网站时将网站向下滚动到特定元素,您可以使用具有 id 的元素来执行此操作:
将 #idnamehere 添加到您正在搜索的网址末尾。页面上必须存在具有该 id 名称的元素。
例如,比较这些 URL 以及在 URL 地址栏中输入它们时得到的内容:
https://travel.usnews.com/rankings/worlds-best-vacations
https://travel.usnews.com/rankings /worlds-best-vacations/#vote-to-add-section
末尾带有 #vote-to-add-section 的会自动向下滚动到 id 的元素#投票添加部分。
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.
你试过这个吗? http://jquerytools.org/documentation/toolbox/mousewheel.html
一个“控制鼠标滚轮”的插件:)
Have you tried this? http://jquerytools.org/documentation/toolbox/mousewheel.html
A plugin to "take control of the mousewheel" :)
尝试:
.trigger("mousewheel", {wheelDelta: 100})
(完全未经测试。灵感来自 在 div 上时绑定到滚轮)
Try:
.trigger("mousewheel", {wheelDelta: 100})
(Completely untested. Inspired by Binding to the scroll wheel when over a div)
实际上这效果更好:
actually this works better:
您好,您可以通过添加事件侦听器来做到这一点。我已经搜索了相同的内容并得到了下面的代码片段并且它正在工作。 相同要求,
检查您是否有基于增量变量的
您可以编写自己的自定义功能。在 html 5 中,正在处理鼠标滚动事件,您也可以尝试这种方式
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