请看这个小提琴
当左div的高度为400px时,我希望滚动div停止跟随。
有没有使用CSS的解决方案。或者我需要添加其他html元素?
如果必须使用JavaScript,该怎么做?
试试下面的小提琴。如果我能纠正你的问题,但不能完全确定,你可能想要这个。。
Fiddle:http://jsfiddle.net/JjuQu/35/
演示:http://jsfiddle.net/JjuQu/35/embedded/result/
你的意思是这样的吗
我使用了javascriptjQuery库。如果你不知道如何使用jQuery,请留下回复
(点击滚动并移动鼠标以获得更好的滚动效果)
const $scroll = $('#scrol');
$(window).on("scroll", function(){
const st = $(this).scrollTop();
if( st >= 240){
$scroll.css({position: "absolute", top: 330});
}else{
$scroll.css({position: "fixed", top: 100});
}
});