<div class="Links">
<h3>123</h3>
<span class="prex">上一頁(yè)</span><span class="next">下一頁(yè)</span>
<div class="picBd">
<ul>
<li><a href="#"><img src='#' border='0' width='89' height='103'/></a></li>
<li><a href="#"><img src='#' border='0' width='89' height='103'/></a></li>
</ul>
</div>
</div>
jquery代碼
<script>
$(function(){
var page = 1;
var i = 11;
var $pre = $('.brands span.pre')
var $next = $('.brands span.next');
var $showMoney = $(".showMoney");
var $autoFun;
//@Mr.Think***調(diào)用自動(dòng)滾動(dòng)
autoSlide();
//@Mr.Think***向前滾動(dòng)
$next.click(function(){
var $parent = $(this).parents("div.all");
var $p_show = $parent.find("div.showMoney");
var $content = $parent.find("div.brands");
var p_width = $content.width();
var len = $p_show.find("li").length;
var page_count = Math.ceil(len / i);
if(!$p_show.is(":animated")){
if(page == page_count){
$p_show.animate({left:"0px"},"slow");
page = 1;
}else{
$p_show.animate({left:'-='+p_width},"slow");
page++;
}
}
});
//@Mr.Think***停止?jié)L動(dòng)
clearFun($showMoney);
clearFun($pre);
clearFun($next);
clearFun($num);
//@Mr.Think***事件劃入時(shí)停止自動(dòng)滾動(dòng)
function clearFun(elem){
elem.hover(function(){
clearAuto();
}, function(){
autoSlide();
});
}
function autoSlide(){
$next.trigger('click');
$autoFun = setTimeout(autoSlide, 1000);//此處不可使用setInterval,setInterval是重復(fù)執(zhí)行傳入函數(shù),這會(huì)引起第二次劃入時(shí)停止失效
}
//@Mr.Think***清除自動(dòng)滾動(dòng)
function clearAuto(){
clearTimeout($autoFun);
}
$pre.click(function(){
var $parent = $(this).parents("div.all");
var $p_show = $parent.find("div.picBd");
var $content = $parent.find("div.brands");
var p_width = $content.width();
var len = $p_show.find("li").length;
var page_count = Math.ceil(len / i);
if( !$p_show.is(":animated") ){
if( page == 1 ){
$p_show.animate({ left : '-='+p_width*(page_count-1) }, "slow");
page = page_count;
}else{
$p_show.animate({ left : '+='+p_width }, "slow");
page--;
}
}
});
});
</script>