jquery 图片水平滚动代码

<html>
<head>
<script type="text/javascript" src="jquery-1.7.1.js"></script>

<style type="text/css"><!--
.clear{clear:both;float:none}
#showPic{border:1px solid #CCC}
#showPic ul li{line-height:80px;background:#CCF}
--></style>

<script type="text/javascript"><!--
(function($){
 
 $.fn.scrollPic=function(_options){
  var defaults={
   height:"80px",
   width:"800px",
   itemWidht:"80px",
   itemMargin:"4px",
   speed:30
   };
  var opts=$.extend(defaults,_options);
  this.each(function(){
   //设置样式
   var _itemWidth=parseInt(opts.itemWidht)+parseInt(opts.itemMargin)*2;
   var _totalWidth=_itemWidth*$(this).find("li").size();
   var _thisObject=$(this);
   var _scrollStatic=true;
   var _ulObject=_thisObject.find("ul");
   var _itemHeight=parseInt(opts.height)-parseInt(opts.itemMargin)*2;
   _thisObject.css({width:opts.width,height:opts.height,overflow:"hidden"})
   _ulObject.css({width:_totalWidth+"px",margin:"0px",padding:"0px","list-style-type":"none"})
   _ulObject.find("li").css({width:opts.itemWidht,margin:opts.itemMargin,float:"left",height:_itemHeight});
   scrollMain=function(){
    _thisObject.find("ul").animate({"margin-left":"-=2px"},opts.speed,"swing",function(){
     if(! _scrollStatic)
      return;
     var _marginLeft=parseInt(_ulObject.css("margin-left"));
     if(_marginLeft+_itemWidth<0){
      _ulObject.append(_ulObject.find("li:first").clone());
      _ulObject.find("li:first").remove();
      _ulObject.css("margin-left",(_marginLeft+_itemWidth)+"px");
     }
     _timeId=setTimeout(scrollMain,0);
    })
   };
   _thisObject.hover(function(){
    //alert(_timeId);
    clearTimeout(_timeId);
    _scrollStatic=false;
    
   },function(){
    _timeId=setTimeout(scrollMain,10);
    _scrollStatic=true;
   });
   scrollMain();
   
  });
 
 }
})(jQuery);

$(function(){
 $("#showPic").scrollPic({height:"120px",speed:10});
});

//--></script>
</head>
<body>
<div id="showPic">
 <ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
  <li>4</li>
  <li>5</li>
  <li>6</li>
  <li>7</li>
  <li>8</li>
  <li>9</li>
  <li>10</li>
 </ul>
</div>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值