<html>
<head>
<title>left to right</title>
</head>
<script type="text/javascript">
function onload() {
window
.setInterval(
function() {
var marginLeft = document
.getElementById("leftToRight").style.marginLeft
moveAfterLeft = marginLeft.substr(0, marginLeft.length - 2) * 1 + 50
if (moveAfterLeft <screen.width - 150) {
document.getElementById("leftToRight").style.marginLeft = moveAfterLeft
} else {
clearInterval()
}
}, 100)
}
</script>
<body onload="onload()">
<ul>
<li id="leftToRight" style="margin-left: 0width: 100px">left to
right</li>
</ul>
</body>
</html>
这是JS<script type="text/javascript">
$(function(){
var speed = 30
var topscroll = document.getElementById("divkuaixunxinxi")
var scrolla = document.getElementById("topscrolla")
var scrollb = document.getElementById("topscrollb")
var scroll = document.getElementById("scroll")
var isIE6_7 = false
if($.browser.msie&&($.browser.version == "6.0")&&!$.support.style || $.browser.msie&&($.browser.version == "7.0")){
scroll.style.width="1600px"
isIE6_7 = true
}else{
scroll.style.width=(scrolla.offsetWidth*2-50)+"px"
}
scrollb.innerHTML = scrolla.innerHTML
function Marquee() {
if (scrollb.offsetWidth - topscroll.scrollLeft <=0)
topscroll.scrollLeft -= scrolla.offsetWidth
else {
topscroll.scrollLeft++
if(isIE6_7 && topscroll.scrollLeft > 1718){
topscroll.scrollLeft -= scrolla.offsetWidth
}
}
}
var mar = setInterval(Marquee, speed)
topscroll.onmouseover = function() { clearInterval(mar) }
topscroll.onmouseout = function() { mar = setInterval(Marquee, speed) }
})
</script>
这是HTML
<div id="divkuaixunxinxi" class="kuaixunxinxi">
<div id="scroll">
<div id="topscrolla">
·<a>平价私享天堂假期3日梦幻爱昵岛</a>平价私享天堂假期3日梦幻爱昵岛&nbsp&nbsp·平价私享天堂假期3日梦幻爱昵岛&nbsp&nbsp·平价私享天堂假期3日梦幻爱昵岛&nbsp&nbsp·平价私享天堂假期3日梦幻爱昵岛
</div>
<div id="topscrollb">
</div>
</div>
</div>