javascript左右滚动(跑马灯)

<html>
<style type="text/css">
body{
    margin:0;
    padding:0;
    background:#fff;
    font: 70% Arial, Helvetica, sans-serif;
}
#scrlContainer{
    visibility:hidden;
    background:#f1f1f1;
    position:relative;
    overflow:hidden;
    width:550px;
    height:20px;
    line-height:20px;
    margin:1em;
}


#scrlContent{
    position:absolute;
    left:0;
    top:0;
    white-space:nowrap; /*如何处理空白,nowrap即不换行*/
}
</style>
<script type="text/javascript" language="Javascript">
var scrlSpeed = 1
//decreasing speed for mozilla
scrlSpeed = (document.all) ? scrlSpeed : Math.max(1, scrlSpeed - 1)


function initScroll(container, object) {
 if (document.getElementById(container) != null) {
  var contObj = document.getElementById(container);
  var obj = document.getElementById(object);
  contObj.style.visibility = "visible";
  contObj.scrlSpeed = scrlSpeed;
  widthContainer = contObj.offsetWidth;
  obj.style.left = parseInt(widthContainer) + "px";
  widthObject = obj.offsetWidth;
  interval = setInterval("objScroll('" + container + "','" + object
    + "'," + widthContainer + ")", 20);
  contObj.onmouseover = function() {
   contObj.scrlSpeed = 0;
  }
  contObj.onmouseout = function() {
   contObj.scrlSpeed = scrlSpeed;
  }
 }
}


function objScroll(container, object, widthContainer) {
 var contObj = document.getElementById(container);
 var obj = document.getElementById(object);
 widthObject = obj.offsetWidth;
 if (parseInt(obj.style.left) > (widthObject * (-1))) {
  obj.style.left = parseInt(obj.style.left) - contObj.scrlSpeed + "px";
 } else {
  obj.style.left = parseInt(widthContainer) + "px";
 }
}
</script>
<body οnlοad="initScroll('scrlContainer', 'scrlContent');">
<div id="scrlContainer">
    <div id="scrlContent">Some very, very useful information will
appear here, yet it will move around your screen so it will be hard to
read it. But the client wants it, so here it is. </div>
</div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值