2017-03-07 80 views
0

的淡出我找到了一個好劇本,將我的項目 工作,但無法弄清楚如何使圖像淡入淡出,並用這個腳本淡入和圖像

$(document).ready(function() { 
    var activeId = $(".active").each(function(){ 
     $("#content" + $(this).attr("id").replace("tab","")).show(); 
    }); 
    $(".tabs a").click(function() { 
     var $tabs =$(this).closest(".tabs"); 
     $("#content" +$tabs.attr("data-lastContent")).hide(); 
     $(this).closest(".tabs").find(".active").removeClass("active"); 
     $(this).addClass("active") 
     var id = $(this).closest("li").attr("id").replace("tab",""); 
     $tabs.attr("data-lastContent", id); 
     $("#content" + id).show(); 

    }); 

}); 

http://jsfiddle.net/hKMFb/446/

+0

最好是你問一個問題之前進行搜索[所以]。用['.fadeIn()'](http://api.jquery.com/fadein/)替換'.show()'和用''.fadeOut()']替換'.hide()'(http:/ /api.jquery.com/fadeout/)。請參閱鏈接頁面以瞭解選項語法 –

+0

你有什麼嘗試?您提供了一個可用的「標籤」腳本,但不提供您嘗試過的更改。 –

+0

http://jsfiddle.net/hKMFb/451/ –

回答

0

您需要在hide()和show()方法中保持淡入淡出速度。 它可能對你的工作如下鏈接例子中提到的: http://jsfiddle.net/hKMFb/450/

$(document).ready(function() { 
    var activeId = $(".active").each(function(){ 
     $("#content" + $(this).attr("id").replace("tab","")).show(1000); 
    }); 
    $(".tabs a").click(function() { 
     var $tabs =$(this).closest(".tabs"); 
     $("#content" +$tabs.attr("data-lastContent")).hide(1000); 
     $(this).closest(".tabs").find(".active").removeClass("active"); 
     $(this).addClass("active"); 
     var id = $(this).closest("li").attr("id").replace("tab",""); 
     $tabs.attr("data-lastContent", id); 
     $("#content" + id).show(1000); 

    }); 

}); 

您也可以使用fadeIn()和​​動畫

$(document).ready(function() { 
    var activeId = $(".active").each(function(){ 
     $("#content" + $(this).attr("id").replace("tab","")).fadeIn(1000); 
    }); 
    $(".tabs a").click(function() { 
     var $tabs =$(this).closest(".tabs"); 
     $("#content" +$tabs.attr("data-lastContent")).fadeOut(1000).hide(); 
     $(this).closest(".tabs").find(".active").removeClass("active"); 
     $(this).addClass("active"); 
     var id = $(this).closest("li").attr("id").replace("tab",""); 
     $tabs.attr("data-lastContent", id); 
     $("#content" + id).fadeIn(1000); 

    }); 
}); 
+0

這是好的,但它調整我的div每次它改變圖像,它會創建動畫隊列 –