我有這段代碼讓div滑動打開和關閉,問題是我希望它默認打開。加載時觸發jQuery函數
$(document).ready(function() {
$('.slider').each(function() {
var current = $(this);
current.attr("box_h", current.height());
});
$(".slider").css("height", sliderHeight);
$(".slider_menu").html('<a href="javascript:void(0)">More <img src="images/more_down.gif" border="0"></a>');
$(".slider_menu a").click(function() {
openSlider()
});
});
function openSlider() {
var open_height = $(".slider").attr("box_h") + "px";
$(".slider").animate({
"height": open_height
}, {
duration: "slow"
});
$(".slider_menu").html('<a href="javascript:void(0)">Close <img src="images/more_up.gif" border="0"></a>');
$(".slider_menu a").click(function() {
closeSlider()
})
};
function closeSlider() {
$(".slider").animate({
"height": sliderHeight
}, {
duration: "slow"
});
$(".slider_menu").html('<a href="javascript:void(0)">More <img src="images/more_down.gif" border="0"></a>');
$(".slider_menu a").click(function() {
openSlider()
})
};
我怎樣才能觸發它打開一次頁面加載?
是否有一個原因,您沒有使用.slideToggle()而不是你的手工製作的openSlider和closeSlider? –