Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在一个div中滚动顶部_Javascript_Html_Scrolltop - Fatal编程技术网

Javascript 在一个div中滚动顶部

Javascript 在一个div中滚动顶部,javascript,html,scrolltop,Javascript,Html,Scrolltop,我已经创建了一个可滚动的div,并尝试使用scrolltop仅在所述div容器中滚动 无论它如何滚动整个身体,我都无法取得任何进展,让它以我想要的方式工作 我最好的猜测是它可能与下面的脚本有关 y1 = document.getElementById('sheet').scrollTop; y2 = y1 + window.innerHeight; yb = parseInt((y + h) * scale) + y_offset + scrollMargin; yt = parseInt(y

我已经创建了一个可滚动的div,并尝试使用scrolltop仅在所述div容器中滚动

无论它如何滚动整个身体,我都无法取得任何进展,让它以我想要的方式工作

我最好的猜测是它可能与下面的脚本有关

y1 = document.getElementById('sheet').scrollTop;
y2 = y1 + window.innerHeight;
yb = parseInt((y + h) * scale) + y_offset + scrollMargin;
yt = parseInt(y * scale) + y_offset - scrollMargin;
if(yt < y1){
 scrollTo(0,yt)
}
if(yb > y2){
 scrollTo(0, yb - window.innerHeight)
}
y1=document.getElementById('sheet').scrollTop;
y2=y1+窗内高度;
yb=parseInt((y+h)*比例)+y_偏移量+滚动边距;
yt=parseInt(y*比例)+y_偏移量-滚动边距;
如果(yty2){
滚动到(0,yb-window.innerHeight)
}
下面是我试图解决的问题的一个例子的链接。

正如您所看到的,它移动整个身体,而不仅仅是在div容器中滚动


任何帮助都将不胜感激,谢谢

这把小提琴可能会对你有所帮助

阅读
$('#scrollBtn').click(function(){
    $('.sss').animate({
    scrollTop: $(".test1").offset().top
}, 100);
});