gpt4 book ai didi

css - 将一个 div 滚动到另一个 div 上

转载 作者:太空宇宙 更新时间:2023-11-04 12:23:07 25 4
gpt4 key购买 nike

是否可以在第二个 div 滚动之前看到顶部 div 中的所有内容。

检查 fiddle

http://jsfiddle.net/KyP8L/91/

非常感谢您的关注。

.div-top{
height:auto;
min-height:100%;
width:100%;
position:fixed;
top:0;
left:0;
background:#ff0;
z-index:500;
}


.div-bottom {
width:100%;
background:#0ff;
margin-top:100%;
z-index:600;
position:relative;
}

最佳答案

虽然 css 无法满足您的需求,但您可以使用 jquery 实现:http://jsfiddle.net/KyP8L/92/

只需检查滚动条,如果到达顶部,则将 z-index(更高)分配给 .div-bottom

$(window).on('scroll',function(){
$(window).scrollTop() ;
;

if($(window).scrollTop()> parseInt($('.div-bottom').css('margin-top')))
{
$('.div-bottom').css('z-index','600');
}else{
$('.div-bottom').css('z-index','0');
}

console.log('top'+$('.div-bottom').css('margin-top'))
console.log('scroll'+$(window).scrollTop())

});

编辑:

As the OP says in comments what he wants is, to be able to scroll down the top div and then I want the bottom div to scroll over the top div

这是 fiddle http://jsfiddle.net/KyP8L/108/

关于css - 将一个 div 滚动到另一个 div 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28214807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com