gpt4 book ai didi

jquery - 在滚动上使用 jquery/css 将 div 从相对位置设置为固定

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

我试图让一个 div 在相对位置和滚动上的固定位置之间设置动画,所以当你向下滚动时,你会看到 div 从它的相对位置滑到右边(固定位置),这样它就可以现在跟随您进入页面。

我正在为滚动功能使用航路点,并使用 jquery 添加一个类,然后我尝试使用 css 动画来让它工作。到目前为止,它会淡化背景颜色,然后跳到右边。我希望让它滑过。任何想法/帮助都会很棒。

这是我的代码:

航点/jquery:

$('.course-list').waypoint(function(direction){
if(direction === 'down'){
$('.course-list').addClass('side-bar');
} else {
$('.course-list').removeClass('side-bar');
}
},{offset:'66px'});

注意:我也尝试过将持续时间添加到 add/removeClass,但对我不起作用。

CSS:

section.content .introduction ul.course-list{position:relative;margin:0;padding:0;list-style:none;-webkit-transition: all 1.5s ease;-moz-transition: all 1.5s ease;-o-transition: all 1.5s ease;transition: all 1.5s ease}

section.content .introduction ul.course-list.side-bar{-webkit-animation:slideRight 1.5s forwards;-moz-animation:slideRight 1.5s forwards;-o-animation:slideRight 1.5s forwards;animation:slideRight 1.5s forwards}

@-webkit-keyframes slideRight{
to{position:fixed;top:0;bottom:0;right:0;background:#ff9}
}
@-moz-keyframes slideRight{
to{position:fixed;top:0;bottom:0;right:0;background:#ff9}
}
@-o-keyframes slideRight{
to{position:fixed;top:0;bottom:0;right:0;background:#ff9}
}
@keyframes slideRight{
to{position:fixed;top:0;bottom:0;right:0;background:#ff9}
}

注意:我也试过设置为绝对定位,它仍然对我不起作用..

HTML:

<ul class="course-list">
<li>Testing only</li>
<li>Testing only</li>
<li>Testing only</li>
<li>Testing only</li>
<li>Testing only</li>
</ul>

fiddle :

https://jsfiddle.net/gpv38jsv/

(它设置为立即执行,所以只需点击“运行”,您就会看到跳跃)

最佳答案

希望这对您有所帮助,我没有太多时间,但您可以从其他 Angular 来解决这个问题。告诉我它是怎么回事,这是一个你可以遵循的想法

$(window).scroll(function(e){
if(this.scrollY > 66){
$('.course-list').addClass('side-bar');
$('.course-list').css({top:this.scrollY})
}else{
$('.course-list').removeClass('side-bar');
$('.course-list').css({top:0})
}
})
ul.course-list{
position:relative;
left:0;margin:0;padding:0;transition: all 1s linear;display:inline-block;right:auto;}

ul.course-list.side-bar{

left:calc(100% - 200px);
}

body{
height:1000000px;
position:relative;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<ul class="course-list">
<li>Testing only</li>
<li>Testing only</li>
<li>Testing only</li>
<li>Testing only</li>
<li>Testing only</li>
</ul>
</body>

关于jquery - 在滚动上使用 jquery/css 将 div 从相对位置设置为固定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48334629/

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