通常、既存のスライダー スクリプトへのリンクをいくつか提供しますが、サイズ変更を適切に処理するものは知りません。
だから私は自分のPHP例外ハンドラからいくつかのコードを適応させました:)
$('#list').each(function(){
var list = $(this),
currentPos = 0,
itemCount = list.children().length;
$('.right, .left').click(function(){
// +100 = right, -100 = left
var direction = $(this).hasClass('right') ? 100 : -100,
nextIndex = direction > 0 ? currentPos + 1 : currentPos - 1;
// do nothing if there is animation happening,
// or if index is out of boundaries
if($('> li', list).is(':animated')
|| (direction > 0 && nextIndex > itemCount - 1)
|| (direction < 0 && nextIndex < 0)
) return;
var next = $('> li:eq(' + nextIndex + ')', list),
current = $('> li:eq(' + currentPos + ')', list);
currentPos = nextIndex;
// determine if the link needs to be hidden
$('.left, .right').removeClass('hide');
if(currentPos === 0 || currentPos === itemCount - 1)
$(this).addClass('hide');
// adjust height of the container
list.css('height', Math.max(current.outerHeight(true), next.outerHeight(true)) + 'px');
// make the current slide absolute
current.css({
position: 'absolute',
left: 0,
top: 0,
width: '100%',
height: current.outerHeight(true) + 'px'
});
// show the next slide
next.css({
position: 'absolute',
left: direction + '%',
top: 0,
width: '100%',
height: next.outerHeight(true) + 'px'
}).show().animate({left: '0%'}, 300, 'swing', function(){
next.css({
position: 'relative',
left: 'auto',
top: 'auto'
});
});
// hide the current slide
current.animate({left: (-direction) + '%'}, 300, 'swing', function(){
current.hide();
});
});
// mouse wheel action within the list area
list.mousewheel(function(event, delta){
(delta > 0) ? $('.right').click() :$('.left').click();
});
});
CSS:
.hide{
display:none;
}
#list{
position: relative;
width: 100%;
overflow: hidden;
}
#list > li{
display: none;
}
#list > li:first-child{
display: block;
}
HTML 構造は次のようになります。
<a class="left"> left </a>
<a class="right"> right </a>
<ul id="list">
<li> ... </li>
...
</ul>
デモ
マウスホイールjQuery プラグイン。マウスホイールのサポートが必要ない場合は、最後のイベントを削除してください。