1??直接利用標(biāo)簽marquee(但這種方法貌似已經(jīng)唄W3C放棄了植捎,不建議使用)
<ul class="list">
<marquee direction="up" onmouseout="this.start()" onmouseover="this.stop()" scrollamount="4">
<c:forEach items="${releaseList}" var="release" begin="0" end="4">
<li><a onclick="seeDatil('${release.id }');"><span>·</span>
${release.title }</a></li>
</c:forEach>
</marquee>
<!-- direction屬性:設(shè)置滾動(dòng)方式
onmouseout屬性:設(shè)置當(dāng)鼠標(biāo)離開時(shí)要做什么
onmouseover屬性:設(shè)置當(dāng)鼠標(biāo)移到上面時(shí)要做什么
scrollAmount屬性:設(shè)置滾動(dòng)的速度。1為最慢 -->
</ul>
2??原生的js,編寫的方法昌抠。(這個(gè)挺好,也行的)
<ul class="list" id="c1">
<c:forEach items="${releaseList}" var="release" begin="0" end="5">
<li><a onclick="seeDatil('${release.id }');">
<span>·</span>${release.title }</a></li>
</c:forEach>
</ul>
<ul class="list" id="c2"></ul>
#ca ul {
margin: 0;
}
#ca {
overflow: hidden;
height: 100px;
}
var c1 = document.getElementById("c1");
var c2 = document.getElementById("c2");
var ca = document.getElementById("ca");
/*將第一個(gè)ul的值賦值給第二個(gè) 當(dāng)?shù)谝粋€(gè)頭部消失時(shí) 由第二個(gè)來(lái)顯示*/
c2.innerHTML = c1.innerHTML;
var cas = null;
window.onload = function() {
st();
}
cas = setInterval('st()', 50);
function st() {
/*如果滾動(dòng)長(zhǎng)度大于第一個(gè)ul的高度 就需要將第一個(gè)ul回到原處 */
if (ca.scrollTop >= c1.offsetHeight) {
ca.scrollTop = 0;
} else {
ca.scrollTop++;
}
/*鼠標(biāo)移入就清除清除定時(shí)器*/
ca.onmouseover = function() {
clearInterval(cas);
}
ca.onmouseout = function() {
cas = setInterval('st()', 50);
}
}
3??簡(jiǎn)單易用的無(wú)縫滾動(dòng)鲁僚。jquery的kxbdMarquee實(shí)現(xiàn)炊苫。(推薦)
=》這種實(shí)現(xiàn)需要多引入一個(gè)js(jquery.kxbdmarquee.js)這個(gè)js網(wǎng)上找吧,如果找不到的可以留言冰沙,我會(huì)給你發(fā)侨艾。
<script type="text/javascript" src="${basePath }/static/plugins/jquery/jquery.kxbdmarquee.js"></script>
<ul class="list">
<c:forEach items="${releaseList}" var="release" begin="0" end="5">
<li><a onclick="seeDatil('${release.id }');"><span>·</span>${release.title }</a></li>
</c:forEach>
</ul>
#marquee {
overflow: hidden;
}
$("#marquee").kxbdMarquee({
isEqual : true, //所有滾動(dòng)的元素長(zhǎng)寬是否相等,true,false
loop : 0, //循環(huán)滾動(dòng)次數(shù),0時(shí)無(wú)限
direction : "up", //滾動(dòng)方向拓挥,"left","right","up","down"
scrollAmount : 1, //步長(zhǎng)
scrollDelay : 200 //時(shí)長(zhǎng)
});
??????