简体   繁体   English

如何在JavaScript中将onmouseover事件更改为onclick?

[英]How to change onmouseover event to onclick instead in javascript?

I am using this plugin in wordpress 我在wordpress中使用此插件

http://www.iwebix.de/front-slider-wordpress-plugin-demo/ http://www.iwebix.de/front-slider-wordpress-plugin-demo/

As you can see in the demo above, the left and right arrow buttons are the controls for scrolling the thumbnails and the event is onmouseover and onmouseout. 正如您在上面的演示中所看到的,左右箭头按钮是滚动缩略图的控件,事件为onmouseover和onmouseout。

I don't know how to change this to onclick instead so that the thumbnails will scroll left and right only when the buttons are clicked. 我不知道如何将其更改为onclick,以便仅在单击按钮时缩略图才会左右滚动。

Any help or ideas on how to do this? 有关如何执行此操作的任何帮助或想法?

Thanks! 谢谢!

Here is the script. 这是脚本。

http://www.iwebix.de/wp-content/plugins/front-slider/scripts/slider.js http://www.iwebix.de/wp-content/plugins/front-slider/scripts/slider.js

I haven't got time to look at it in detail (or test it), but at first glance you should be able to change the onmouseover & onmouseout events to onmousedown and onmouseup events and it looks like it'll all still work. 我没有时间详细研究(或测试)它,但是乍一看,您应该可以将onmouseoveronmouseout事件更改为onmousedownonmouseup事件,并且看起来它们仍然可以使用。 In other words change this (lines 28-30): 换句话说,更改此设置(第28-30行):

u.onmouseover=new Function('SLIDE.scroll.init("'+this.thumbs+'",-1,'+this.scrollSpeed+')');
u.onmouseout=r.onmouseout=new Function('SLIDE.scroll.cl("'+this.thumbs+'")');
r.onmouseover=new Function('SLIDE.scroll.init("'+this.thumbs+'",1,'+this.scrollSpeed+')');

to this: 对此:

u.onmousedown=new Function('SLIDE.scroll.init("'+this.thumbs+'",-1,'+this.scrollSpeed+')');
u.onmouseup=r.onmouseup=new Function('SLIDE.scroll.cl("'+this.thumbs+'")');
r.onmousedown=new Function('SLIDE.scroll.init("'+this.thumbs+'",1,'+this.scrollSpeed+')');

Hopefully that helps. 希望有帮助。 Sorry in advance if it doesn't... 抱歉,如果没有,请提前...

A little hacky, but the absolutely easiest way to do this is to just bind the onmouseover event handler directly to onclick and the clear onmouseover so that the handler is only fired by the onclick. 有点棘手,但绝对简单的方法是将onmouseover事件处理程序直接绑定到onclick和clear onmouseover,以便该处理程序仅由onclick触发。 Like this: 像这样:

var divLeftArrow = document.getElementById("arrowleft");
divLeftArrow.onclick = divLeftArrow.onmouseover;
divLeftArrow.onmouseover = undefined;

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

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