我認爲用jQuery創建自己的自定義內容滑塊很容易,並且設法創建一個體面的滑塊。在滑塊包裝器中,我有一個滑塊內容和滑塊列表。滑塊僅顯示三個內容區域中的一個。自定義jQuery滑塊上的奇怪行爲
這是滑塊的HTML:
<div id="featured_wrapper">
<ul id="featured_content">
<li class="item" id="item-3">
<h1>Title item 3</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
</li>
<li class="item" id="item-2">
<h1>Title item 2</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
</li>
<li class="item" id="item-1">
<h1>Title item 1</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
</li>
</ul><!--/featured_content-->
<ul id="featured_list">
<li class="item-link" id="item-link-3">
<div class="item-container">
<h2>Title item 3</h2>
</div>
</li>
<li class="item-link" id="item-link-2">
<div class="item-container">
<h2>Title item 2</h2>
</div>
</li>
<li class="item-link" id="item-link-1">
<div class="item-container">
<h2>Title item 1</h2>
</div>
</li>
</ul><!--/featured_list-->
</div><!--/featured_wrapper-->
#featured_content
是內容div
,並且#featured_list
是列表div
。
這是CSS:
#featured_wrapper { background: transparent url('/Files/System/web/gfx/featured_content_item_bg.jpg') repeat-x top left; overflow: hidden; }
#featured_content { float: left; height: 390px; width: 622px; background: transparent url('/Files/System/web/gfx/featured_content_item_bg.jpg') repeat-x top left; position: relative; }
#featured_content li { position: absolute; display: block; width: 622px; height: 390px; }
#featured_list { float: right; height: 390px; width: 338px; background: transparent url('/Files/System/web/gfx/featured_content_list_bg.png') repeat-y 0 -260px; }
.item-link { height: 70px; padding: 30px 20px 30px 45px; cursor: pointer; }
.item-link h2 { font-weight: bold; font-size: 16px; line-height: 1; }
這裏是jQuery代碼:
var bgpos = new Array();
bgpos[0] = -260;
bgpos[1] = -130;
bgpos[2] = 0;
$('#featured_content .item:not(:first-child)').css({'opacity': 0, 'margin-top': -20});
$('#featured_content .item:first-child').addClass('visible');
$('#featured_list .item-link').click(function(){
var item = $(this).attr('id').split('-');
var item_index = $(this).index();
var item_id = 'item-' + item[2];
/*
$('#featured_content .item:not(#' + item_id + ')').fadeOut('fast');
$('#featured_content #' + item_id).fadeIn('fast');
*/
$('#featured_content .item:not(#' + item_id + ')').animate({
marginTop: -20,
opacity: 0
}, 200).addClass('visible');
$('#featured_content #' + item_id).animate({
marginTop: 0,
opacity: 1
}, 200).removeClass('visible');
$('#featured_list').stop().animate({'backgroundPosition': '(0 ' + bgpos[item_index] + 'px)'}, {duration: 200});
});
的問題是,即使第一個項目(項目-3)是可見的,文本ISN不可選擇,但它下面的圖層是。嘗試一下這個測試頁面上的內容區域中的鏈接我已經設置了:
http://dev.drumroll.no/jquery-slider-fail/
似乎在Windows XP上運行ff3.5.7可以正常工作。你正在使用哪種瀏覽器? – Flatlin3 2010-01-19 11:25:20
我使用的是Safari 4.0.4,但我也使用與您相同的瀏覽器對其進行了測試。您是否可以點擊顯示的第一個項目上的鏈接?如果您嘗試點擊並拖動第一個項目的圖片會發生什麼情況? (當我在Safari中單擊並拖動圖像時,它會顯示內容區域中最後一張圖片的縮略圖。) – 2010-01-19 11:50:40