我像jQuery有一個onload事件功能:
$(function() {
$('.over').hover(function() {
//FIRST PARAMETER RIGT, LEFT, TOP, BOTTOM
if ($(this).attr('data-direction') == 'right') {
$(this).addClass('flipping-right');
}
else if ($(this).attr('data-direction') == 'left') {
$(this).addClass('flipping-left');
}
else if ($(this).attr('data-direction') == 'top') {
$(this).addClass('flipping-top');
}
//ETC.
//SECOND gal1,gal2,gal3,gal4
if ($(this).attr('gal') == 'gal1'){
img = $(this).find('img');
setTimeout(function() {
img.attr('src', arrFirstYellowCard[i]);
i++;
if(i > arrFirstYellowCard.length-1)
i=0;
}, 100);
}
else if ($(this).attr('gal') == 'gal2'){
img = $(this).find('img');
setTimeout(function() {
img.attr('src', arrSecondPurpleCard[j]);
j++;
if(j > arrSecondPurpleCard.length-1)
j=0;
}, 100);
}
我想一個函數來執行功能每秒,但與參數在像
var array_param = ["right,gal1","top,gal3","bottom,gal4","left,gal2","right,gal5"];
陣列被允許組合
我要像一個計時器,以便每個參數被稱爲每秒
var timer = $.timer($('.over').hover(array_param(0)), 1000);
timer.play();
,但我不知道該如何實現這個功能,以及如何將參數添加到的onload分配的功能:
$(function() { $('.over').hover(function() {...
Please take a look at my jsfiddle
而不是每秒鐘添加新的事件處理程序,您應該每秒更改一次數組,並引用來自一個處理程序的數組。 – Bergi 2013-03-14 16:31:32
可以請你發表樣品嗎? – cMinor 2013-03-14 18:16:46