問題:
I have this a piece of js in my website to switch images but need a delay when you click the image a second time.我在我的網站上有一段 js 來切換圖像,但是當您第二次單擊圖像時需要延遲。 The delay should be 1000ms.延遲應爲 1000 毫秒。 So you would click the img.jpg then the img_onclick.jpg would appear.所以你會點擊 img.jpg 然後 img_onclick.jpg 會出現。 You would then click the img_onclick.jpg image there should then be a delay of 1000ms before the img.jpg is shown again.然後,您將單擊 img_onclick.jpg 圖像,在再次顯示 img.jpg 之前應該有 1000 毫秒的延遲。
Here is the code:這是代碼:
jQuery(document).ready(function($) {
$(".toggle-container").hide();
$(".trigger").toggle(function () {
$(this).addClass("active");
$(".trigger").find('img').prop('src', 'http://localhost:8888/images/img_onclick.jpg');
}, function () {
$(this).removeClass("active");
$(".trigger").find('img').prop('src', 'http://localhost:8888/images/img.jpg');
});
$(".trigger").click(function () {
$(this).next(".toggle-container").slideToggle();
});
});
解決方案:
參考一: https://stackoom.com/question/1D2Me參考二: How to set time delay in javascript