触发鼠标在随机元素上输入 [英] trigger mouse enter on random element
本文介绍了触发鼠标在随机元素上输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个javascript:
I have this javascript:
$('.foto').filter(function(index) {
return index == Math.floor(Math.random() * 8) + 1;
}).trigger('mouseover');
我想在照片上模拟悬停效果,但是滤镜功能不起作用. 我也尝试过
I want to simulate a hover effect on a photo, but somehow the filter function does not work. I also tried
$('.foto:random').trigger('mouseover');
推荐答案
尝试一下:
$.fn.rand = function(){
return this.eq(Math.floor(Math.random()*this.length));
};
$(".foto").rand().trigger("mouseover");
注意:,您只需定义一次$.fn.rand
,通常只需在包含jquery之后即可.
Note: you only have to define $.fn.rand
once, usually right after including jquery.
这篇关于触发鼠标在随机元素上输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文