1

私はこのJavaScriptを持っています:

$('.foto').filter(function(index) {
    return index == Math.floor(Math.random() * 8) + 1;
}).trigger('mouseover');

写真にホバー効果をシミュレートしたいのですが、どういうわけかフィルター機能が機能しません。私も試しました

$('.foto:random').trigger('mouseover');
4

1 に答える 1

3

これを試して:

$.fn.rand = function(){
    return this.eq(Math.floor(Math.random()*this.length));
};
$(".foto").rand().trigger("mouseover");

注:$.fn.rand通常は jquery をインクルードした直後に、一度だけ定義する必要があります。

于 2012-03-01T23:09:36.933 に答える