1
我使用Wordpress插件高級Ajax頁面加載器。爲了在ajax頁面加載後重新加載腳本,我正在使用此重新加載代碼來重新加載圖像滑塊。結合重複的jQuery功能
var metaslider_804 = function(jQuery) {
jQuery('#metaslider_804').flexslider({
slideshowSpeed:6000,
animation:"fade",
controlNav:false,
directionNav:true,
pauseOnHover:true,
direction:"horizontal",
reverse:false,
animationSpeed:600,
prevText:"<",
nextText:">",
easing:"swing",
slideshow:true,
useCSS:false
});
};
var timer_metaslider_804 = function() {
var slider = !window.jQuery ? window.setTimeout(timer_metaslider_804, 100) : !jQuery.isReady ? window.setTimeout(timer_metaslider_804, 100) : metaslider_804(window.jQuery);
};
timer_metaslider_804();
由於我使用在不同的頁面不同的滑塊我重複上面的代碼對於每個滑塊,通過僅改變所述滑塊ID。例如。改變ID 804到824
var metaslider_824 = function(jQuery) {
jQuery('#metaslider_824').flexslider({
slideshowSpeed:6000,
animation:"fade",
controlNav:false,
directionNav:true,
pauseOnHover:true,
direction:"horizontal",
reverse:false,
animationSpeed:600,
prevText:"<",
nextText:">",
easing:"swing",
slideshow:true,
useCSS:false
});
};
var timer_metaslider_824 = function() {
var slider = !window.jQuery ? window.setTimeout(timer_metaslider_824, 100) : !jQuery.isReady ? window.setTimeout(timer_metaslider_824, 100) : metaslider_824(window.jQuery);
};
timer_metaslider_824();
雖然這設置工作,它似乎並不喜歡這樣做的最好方式,尤其是因爲我使用8個滑塊。有沒有更好的做到這一點?例如:
$sliderIDs = "804, 824, xxx, xxx, etc"
var metaslider_$sliderIDs = function(jQuery) {
jQuery('#metaslider_$sliderIDs').flexslider({
slideshowSpeed:6000,
animation:"fade",
controlNav:false,
directionNav:true,
pauseOnHover:true,
direction:"horizontal",
reverse:false,
animationSpeed:600,
prevText:"<",
nextText:">",
easing:"swing",
slideshow:true,
useCSS:false
});
};
var timer_metaslider_$sliderIDs = function() {
var slider = !window.jQuery ? window.setTimeout(timer_metaslider_$sliderIDs, 100) : !jQuery.isReady ? window.setTimeout(timer_metaslider_$sliderIDs, 100) : metaslider_$sliderIDs(window.jQuery);
};
timer_metaslider_$sliderIDs();
輝煌,我嘗試了第二種方法,它完美地工作。謝謝 :) – user18144