文字不间断向上滚动效果完整代码,无缝轮播原理

<!doctype html> <html> <head> <meta charset="utf-8"> <title>不间断向上滚动</title> <script src="http://libs.baidu.com/jquery/1.11.3/jquery.mi...
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>不间断向上滚动</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<div id="xst" style="width:290px;height:170px;">
    <p>测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试111</p>
</div>
<script>
function addEventSimple(obj, evt, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evt, fn, false);
    } else if (obj.attachEvent) {
        obj.attachEvent('on' + evt, fn);
    }
}
addEventSimple(window, 'load', initScrolling);
var scrollingBox;
var scrollingInterval;
var reachedBottom = false;
var bottom;


function initScrolling() {
    scrollingBox = document.getElementById('xst');
    scrollingBox.style.overflow = "hidden";
    scrollingInterval = setInterval("scrolling()", 50);
    scrollingBox.onmouseover = over;
    scrollingBox.onmouseout = out;
}

function scrolling() {
    var origin = scrollingBox.scrollTop++;
    if (origin == scrollingBox.scrollTop) {
        if (!reachedBottom) {
            scrollingBox.innerHTML += scrollingBox.innerHTML;
            reachedBottom = true;
            bottom = origin;
        } else {
            scrollingBox.scrollTop = bottom;
        }
    }
}

function over() {
    clearInterval(scrollingInterval);
}

function out() {
    scrollingInterval = setInterval("scrolling()", 50);
}
</script>

</body>
</html>

你可能感兴趣的文章

相关问题

0 条评论

请先 登录 后评论
admin
admin

651 篇文章

作家榜 »

  1. admin 651 文章
  2. 粪斗 185 文章
  3. 王凯 92 文章
  4. 廖雪 78 文章
  5. 牟雪峰 12 文章
  6. 李沁雪 9 文章
  7. 全易 2 文章
  8. Stevengring 0 文章