为了账号安全,请及时绑定邮箱和手机立即绑定

scrollTop和offsetTop的区别

scrollTop和offsetTop的区别

料青山看我应如是 2018-12-07 08:18:16
/**这个是我转司徒正美的一个图片上下无缝滚动的效果**/<style type="text/css"> #marquee { position: relative; height: 300px; width: 200px; overflow: hidden; border: 10px solid #369; padding:0; margin:0; } #marquee img { display: block; } #marquee dd { margin: 0px; padding: 0px; } </style> <dl id="marquee"> <dt> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s017.jpg" alt="无缝滚动" /> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s018.jpg" alt="无缝滚动" /> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s019.jpg" alt="无缝滚动" /> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s020.jpg" alt="无缝滚动" /> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s021.jpg" alt="无缝滚动" /> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s022.jpg" alt="无缝滚动" /> <img src="http://images.cnblogs.com/cnblogs_com/rubylouvre/199042/o_s023.jpg" alt="无缝滚动" /> </dt> <dd> </dd> </dl> <script type="text/javascript"> var Marquee = function (id) { var container = document.getElementById(id), original = container.getElementsByTagName("dt")[0], clone = container.getElementsByTagName("dd")[0], speed = arguments[1] || 10; clone.innerHTML = original.innerHTML; alert(container.scrollTop); var rolling = function () { if (container.scrollTop == clone.offsetTop) {//我现在纠结的就是container.scrollTop和clone.offsetTop的区别 为什么clone.offsetTop是1050,而外面的container.scrollTop却是0 container.scrollTop = 0; } else { container.scrollTop++; } } var timer = setInterval(rolling, speed) container.onmouseover = function () { clearInterval(timer) } container.onmouseout = function () { timer = setInterval(rolling, speed) } } window.onload = function () { Marquee("marquee"); } </script>
查看完整描述

3 回答

?
POPMUISE

TA贡献1765条经验 获得超5个赞

这个我看了,但测试起来还是很抽象,有没有具体点的

查看完整回答
反对 回复 2018-12-24
  • 3 回答
  • 0 关注
  • 577 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信