gpt4 book ai didi

jquery - ScrollTop jQuery 不透明度基于滚动位置在顶部和底部淡入和淡出

转载 作者:行者123 更新时间:2023-12-01 05:35:54 26 4
gpt4 key购买 nike

我正在寻找一个基于垂直滚动位置显示不透明度的 jQuery 脚本。其中(可见)垂直中间的不透明度为 1,但顶部和底部均淡入不透明度 0。页面上具有相同类名的多个包装器行元素。

.inner.cover
{
height:20%;
}
<div class="inner cover" style="opacity:0;">1 Vertical Top</div>
<div class="inner cover" style="opacity:0.333;">2</div>
<div class="inner cover" style="opacity:1;">3 Vertical Middle</div>
<div class="inner cover" style="opacity:0.333;">4</div>
<div class="inner cover" style="opacity:0;">5 Vertical Bottom</div>
<div class="inner cover" style="opacity:0;">6 Below Vertical Bottom</div>
<div class="inner cover" style="opacity:0;">7 Below Vertical Bottom</div>
<div class="inner cover" style="opacity:0;">8 Below Vertical Bottom</div>
<div class="inner cover" style="opacity:0;">9 Below Vertical Bottom</div>

类似这个网站: https://aibcomms.typeform.com/to/vMZwYQ

有人知道我在哪里/是否可以找到这样的东西吗?如果可能的话,尝试避免使用插件?

最佳答案

也许这个解决方案适合您。祝你好运。现在,您可以自己管理需要在项目中向上向下的方向。

'use strict';
jQuery(function($){

var lines = $('.line');

function setStep(step,move){

$('.line').removeClass('active');
$('.line').removeClass('fog');

$(lines[step]).addClass('active');

switch (move) {
case 'down':
if (lines.length-1 > step){
$(lines[step])
.prev()
.addClass('fog');
$(lines[step])
.next()
.addClass('fog');

step++;

setTimeout(function(){
setStep(step,move);
},2000);

} else {
setStep(lines.length-1,'up');
}
break;
case 'up':
if (0 < step){

$(lines[step]).addClass('active');

if (lines.length-1 !== step ){
$(lines[step])
.next()
.addClass('fog');
}

$(lines[step])
.prev()
.addClass('fog');

step--;

setTimeout(function(){
setStep(step,move);
},2000);

} else {
setStep(0,'down');
}
break;
}
}

//start item active 0
setStep(0,'down');
});
.line{
opacity:0;
display:none;
transition: opacity 0.9s;
}
.fog{
opacity:0.33;
display:block;
transition: opacity 0.9s;
}
.active{
opacity:1;
display:block;
transition: opacity 0.9s;
}
.inner.cover
{
height:20%;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div class="inner cover line" >1 Vertical Top</div>
<div class="inner cover line" >2</div>
<div class="inner cover line" >3 Vertical Middle</div>
<div class="inner cover line" >4</div>
<div class="inner cover line" >5 Vertical Bottom</div>
<div class="inner cover line" >6 Below Vertical Bottom</div>
<div class="inner cover line" >7 Below Vertical Bottom</div>
<div class="inner cover line" >8 Below Vertical Bottom</div>
<div class="inner cover line" >9 Below Vertical Bottom</div>
</body>
</html>

关于jquery - ScrollTop jQuery 不透明度基于滚动位置在顶部和底部淡入和淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34128721/

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