jQuery div autoscroll [英] jQuery div autoscroll

查看:52
本文介绍了jQuery div autoscroll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关如何使用jQuery创建自动滚动效果的建议,这将使页面中的整个div在以恒定的低速加载时开始垂直滚动。这将是一个包含大量内容的div,其中任何时候屏幕上只能看到少量内容。

I am looking for advice on how to create an autoscrolling effect using jQuery which would enable an entire div within a page to begin scrolling vertically upon loading at a constant slow speed. This would be a div with a large amount of content of which only a small amount was visible on the screen at any one time.

滚动需要自动,流畅并且以定义的速率,例如每秒10个像素。另外,当滚动到达页面底部时,我需要能够调用一个函数。

The scroll needs to be automatic, smooth and at a defined rate for example 10 pixels per second. Additionally when the scroll gets to the bottom of the page I need to be able to call a function.

我尝试过几个不同的jQuery插件但是什么都没找到可靠。有人可以建议采取这种方法吗?

I have tried a few different jQuery plugins but found nothing yet that worked reliably. Can anybody suggest an approach to take here?

谢谢

Simon

推荐答案

这可以在没有jquery的情况下轻松完成。

This can easily be done without jquery.

function init() {

    var div = document.getElementById("myDiv");

    // increase the scroll position by 10 px every 10th of a second
    setInterval(function() { 
        // make sure it's not at the bottom
        if (div.scrollTop < div.scrollHeight - div.clientHeight)
            div.scrollTop += 10; // move down
    }, 100); // 100 milliseconds

}

这篇关于jQuery div autoscroll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆