我寫了一些代碼來切換圖像的src,並暫停/恢復jQuery cycle2插件。使用jQuery切換圖像src
我不知道爲什麼它不工作,並希望得到一些幫助。
$('.play-pause').click(function(){
if ($(this).attr('src', '/images/template/pause.png')) {
$(this).attr('src', '/images/template/play.png');
$('.cycle-slideshow').cycle('pause');
} else if ($(this).attr('src', '/images/template/play.png')) {
$(this).attr('src', '/images/template/pause.png');
$('.cycle-slideshow').cycle('resume');
}
});
如果我刪除'else if'語句,第一個'if'語句就起作用。
感謝您的幫助。
傑夫
這是有幫助的。我轉而使用CSS背景,而且它也很乾淨。 – jeffusu
是的,只需使用它並在一行代碼中執行此操作即可:http://api.jquery.com/toggleClass/ –