纯javascript自动滚动到页面底部,然后备份
如果使用jquery,此脚本工作正常:纯javascript自动滚动到页面底部,然后备份,javascript,Javascript,如果使用jquery,此脚本工作正常: $('html, body').animate({ scrollTop: $(document).height() - $(window).height() }, 1000, function() { $(this).animate({ scrollTop: 0 }, 1000); }); 但是,我需要纯JS中的这个。我想这是可能的。我需要页面滚动到底部,然后备份并重复此演示中的步骤: 非常感谢 function scroll(speed) {
$('html, body').animate({ scrollTop: $(document).height() - $(window).height() }, 1000, function() {
$(this).animate({ scrollTop: 0 }, 1000); });
但是,我需要纯JS中的这个。我想这是可能的。我需要页面滚动到底部,然后备份并重复此演示中的步骤:
非常感谢
function scroll(speed) {
document.body.scrollTop = $(document).height() - $(window).height();
setTimeout(function(){
document.body.scrollTop = 0;
},1000);
}
speed = 1000;
scroll(speed)
setInterval(function(){scroll(speed)}, speed * 2);
这是一个快速的模型,希望它能帮助您入门。我是从你那儿得到的
var wrapper=document.getElementById(“wrapper”)//跳伞
var h=包装器。离地高度//获得高度
至(h);
函数滚动到(x){
//过去的
变量e;
//持续时间(毫秒)
var d=1000;
//b与begin一样,从何处开始(您可以动态地获取此信息)
var b=0;
//开始时间,动画开始时
var s=(new Date()).getTime();//开始时间
//魔法
var t=设置间隔(函数(){
//计算经过的时间
e=(新日期()).getTime()-s;
//检查经过的时间是否小于持续时间
if(e
您检查过了吗。我不确定是否有动画,但请尝试执行window.scrollTo(0,document.body.scrollHeight);滚动到(0,0);有时我喜欢看到人们编写他们认为简单的jQuery,然后放入调试器代码>,然后查看浏览器的调试工具。jQuery的指令数量迫使你可怜的浏览器一步一步地去做任何事情。。。令人震惊。没错,而且这个页面每三分钟就会刷新一次覆盆子圆周率,我不想让它承受更大的压力。是的,它没有平滑的滚动!!这正是我想要的,谢谢:3唯一的问题是它不会恢复。
var wrapper = document.getElementById("wrapper"); //get div
var h = wrapper.offsetHeight; //get height
scrollTo(h);
function scrollTo(x) {
//elapsed
var e;
//duration in milli seconds
var d = 1000;
//b as in begin, where to start (you could get this dynamically)
var b = 0;
//start time, when the animation starts
var s = (new Date()).getTime(); //start time
//the magic
var t = setInterval(function () {
//calculate elapse time
e = (new Date()).getTime() - s;
//check if elapse time is less than duration
if (e < d) {
//animate using an easing equation
window.scrollTo(0, ease(e, b, x, d));
} else {
//animation is complete, stop interval timer
clearInterval(t);
t = null;
}
}, 4);
}
//Info about the letters (I think)
//t = elapse time
//b = where to begin
//c = change in comparison to begin
//d = duration of animation
function noease(t, b, c, d) {
t /= d;
return b + c * (t);
}
function ease(t, b, c, d) {
return Math.round(-c * Math.cos(t / d * (Math.PI / 2)) + c + b);
}