[练习3]js学习之图片的竖直滚动

<!DOCTYPE <!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<head>
 <title></title>
 <style type="text/css">
  body{
   font-size: 12px;
   font-family: 'Mirosoft YaHei','微软雅黑','SimSun','宋体';
   background: #FFFFFF;
   margin: 0px;
   padding: 0px;
   text-align: center;
   color: #000000;
  }
  img{
   display: block;
   width: 220px;
   height: 70px;
   margin: 5px 0px;
  }
  div.news_root{
   width: 255px;
   height: 134px;
   text-align: left;
   margin: 0 auto;
   background: url(images/bg_news.gif);
   background-repeat: no-repeat;
  }
  div.news_header{
   width: 243px;
   height: 16px;
   vertical-align: top;
   text-align: left;
   font-size: 14px;
   padding: 6px;
  }
  #scrollContainer{
   width: 245px;
   margin: 2px 5px;
   overflow: hidden;/*这里是滚动的关键,将超出边框的部分隐藏,造成了滚动的效果*/
   text-align: left;
  }
 </style>
</head>
<body>
 <div class="news_root">
  <div class="news_header">Headliner</div>
  <div id="scrollContainer">
   <div id="scrollContent">
    <img src="img/1.jpg" alt="企鹅">
    <img src="img/2.jpg">
    <img src="img/3.jpg">
    <img src="img/4.jpg">
    <img src="img/5.jpg">
    <img src="img/6.jpg">
    <img src="img/7.jpg">
    <img src="img/8.jpg">
   </div>
  </div>
 </div>
<script type="text/javascript">
 var stopscroll = false; //设置是否滚动的开关
 var scrollContHeight = 200;
 var scrollContWidth = 230;
 var scrollSpeed = 25;
 var scrollContainer = document.getElementById("scrollContainer");
 var scrollContent = document.getElementById("scrollContent");
 do{
  scrollContainer.appendChild(scrollContent.cloneNode(true));
 }while(scrollContainer.offsetHeight < scrollContHeight);//强制运行一次,复制一次内容到容器中,使滚动看起来更连贯
 scrollContainer.style.width = scrollContWidth + "px";
 scrollContainer.style.height = scrollContHeight + "px";
 scrollContainer.noWrap = true;
 scrollContainer.onmouseover = new Function("stopscroll=true");
 scrollContainer.onmouseout = new Function("stopscroll=false");
 function init () {
  // body...
  scrollContainer.scrollTop = 0;
  setInterval("scrollUp()",scrollSpeed);
 }
 init();
 var currTop = 0;
 function scrollUp(){
  if (stopscroll == true) return;
  currTop = scrollContainer.scrollTop;
  scrollContainer.scrollTop +=1;
  if (currTop == scrollContainer.scrollTop) {
   console.log(currTop + "&&" + scrollContainer.scrollTop)
   scrollContainer.scrollTop = 0;
   scrollContainer.scrollTop += 1;
  }
 }
</script>
</body>
</html>
企鹅

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值