<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>