比方說,我有一些像這樣的代碼:每次我需要它jQuery - 有沒有辦法重新使用參數來減少代碼重複?
jQuery('#retouching-image-1').beforeAfter({
animateIntro: true,
introDelay: 500
});
jQuery('#retouching-image-2').beforeAfter({
animateIntro: true,
introDelay: 500
});
而不是重複animateIntro: true, introDelay: 500
,是有可能把這些值轉換成某種形式的可重複使用的變量?
謝謝。
大多數人都給出了相同的答案,但是這是第一次。謝謝大家:) – Matt
只是一個說明 - 在我的情況下,第一個選項是好的(將參數添加到變量),但我的jQuery函數需要在每個實例上獨立運行,因此是順序ID而不是可重用類。 – Matt