[英]Horizontal div sliding with jQuery
我找到了滿足我需求的這段小代碼,但是有什么方法可以使“ target 1”默認加載? 因此,“正確”不是以空div開始,而是已經包含“目標1”中的內容。
jQuery(function($) {
$('a.panel').click(function() {
var $target = $($(this).attr('href')),
$other = $target.siblings('.active');
if (!$target.hasClass('active')) {
$other.each(function(index, self) {
var $this = $(this);
$this.removeClass('active').animate({
left: $this.width()
}, 500);
});
$target.addClass('active').show().css({
left: -($target.width())
}).animate({
left: 0
}, 500);
}
});
});
要使target1處於活動狀態,默認情況下,您需要給它一個active
類,並在HTML中添加display: block
作為其樣式
通過不使用javascript將target1 div設置為活動狀態,無需在頁面顯示在正確的div中之前先對其進行加載。 這意味着,如果頁面很沉重,它就不會閃爍白色,因為它正在等待頁面加載。
<div class="panel active" id="target1" style="background:green; display:block;">Target 1</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.