<div class="contents " style="overflow: hidden;"> <div class="scroll-box"> <ul class="list clar"> {volist name="articleinfo" id="item"} <li> <div class="art"> <img src="{$item.thumb.0.file}" alt="" width="210px" height="150px"> <div class="art-content"> <h1 class="title" style="line-height:20px;margin:0px;padding:0px;margin-bottom:23px;margin-top:5px;">{$item.title}</h1> <p style="margin:0px;padding:0px;line-height:10px;">来源:{$item.source}</p> <p style="margin:0px;padding:0px;line-height:10px;padding-left:20px;font-weight:none">日期:{:date('Y-m-d',$item.sdate)}</p> <p class="text" style="width:95%;margin-top:20px;line-height:30px;color:#444">{$item.desc}</p> </div> </div> </li> {/volist} </ul> </div>
<script> $(function() { //获得当前<ul> var $uList = $(".scroll-box ul"); // console.log($uList); var timer = null; //触摸清空定时器 $uList.hover(function() { clearInterval(timer); }, function() { //离开启动定时器 timer = setInterval(function() { scrollList($uList); }, 1000); }).trigger("mouseleave"); //自动触发触摸事件 //滚动动画 function scrollList(obj) { console.log($(obj).find("ul li:first")); $(obj).find("li:first").animate({ marginTop: "-20px" }, 1000, function() { console.log($(this)); $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this); //函数appendTo()把第一个挪到最后一个 }); } } )