這是代碼:code on jsfiddle。在第一次運行時,它不顯示「slideDown」動畫,但隨後的時間工作正常。jquery動畫在第一次運行時無法正常工作
$("#more-news") .click(function() {
$(".news-hide") .slideDown('slow').removeClass("hide");
});
這是代碼:code on jsfiddle。在第一次運行時,它不顯示「slideDown」動畫,但隨後的時間工作正常。jquery動畫在第一次運行時無法正常工作
$("#more-news") .click(function() {
$(".news-hide") .slideDown('slow').removeClass("hide");
});
請使用以下內容。
$("#more-news").click(function() {
//changed the line below.
$(".news-hide").hide().removeClass('hide').slideDown('slow');
$("#less-news").fadeIn('slow').removeClass("hide");
$("#more-news").fadeOut().addClass("hide");
});
而是使用多個元件和多種體育賽事,你可以使用這樣,
$("#more-news").click(function() {
var button = $(this)
$(".news-hide").slideToggle(function() {
$(".news-hide").is(":visible") ? button.text("Less News") : button.text("More News")
});
});
自舉類躲不相當的工作方式相同作爲jQuery隱藏功能的方式,創建一個令人困惑的結果。
要圍繞滑動之前jQeuerify你的隱藏thangs,你可以做一點這樣的:
$('.hide').hide().removeClass('hide');
$("#more-news") .click(function() {
$(".news-hide") .slideDown('slow');
});
現在,您不必在每次你做一些時間去擔心該皮革類,但它保持隱藏的東西,直到文檔準備好JavaScript本身。
不回答你的問題,但jQuery有'slideToggle' - 所以你可以刪除一些重複的代碼 - http://api.jquery.com/slidetoggle/ –