简体   繁体   English

使用 onclick 事件触发 function

[英]Trigger function with onclick event

window.addEventListener(mousewheelEvent, _.throttle(parallaxScroll, 60), false);

I have an event listener that listens to a mousewheelEvent to trigger a function, yet trying to trigger that function directly (on a different page, using react) will invariably only pass a mouseclick event.我有一个事件侦听器,它侦听 mousewheelEvent 以触发 function,但尝试直接触发 function(在不同的页面上,使用反应)总是只会传递 mouseclick 事件。 What's something I can listen to via DOM to trigger the function as a mousewheelEvent when someone onclicks a button?当有人点击按钮时,我可以通过 DOM 听什么来触发 function 作为 mousewheelEvent?

Sadly, the attitude of some in this community is outright toxic as indicative by the votes here and in this question...可悲的是,这个社区中一些人的态度是完全有毒的,正如这里和这个问题的投票所表明的那样......

Trigger 'dummy' mouse wheel event 触发“虚拟”鼠标滚轮事件

The short of it, is that you cannot trigger a dummy mouse event.简而言之,您不能触发虚拟鼠标事件。 The second best option is to create a new function that closely matches what the scroll or wheel event triggers and utilize that on the onClick.第二个最佳选择是创建一个新的 function,它与滚动或滚轮事件触发的内容非常匹配,并在 onClick 上使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM