更改移动设备上基于滚动的淡入淡出
changing scroll-based fade on mobile?
我已经将jsFiddle链接到我在这里使用的代码。渐变滚动功能运行良好。我只想能够根据屏幕大小改变渐变率。从本质上讲,我需要它比在较小的屏幕(手机/平板电脑)上更快地消退,因为我的媒体查询的大小发生了变化。
例如:能够调整这些数字
$('#one').css({'opacity':(( **300**-scroll )/ **300**)+0.4});
基于屏幕大小
我在想一个if/else条件,但我对JS和jQuery非常陌生,无法理解。非常感谢。
$(window).scroll(function() {
var scroll = $(window).scrollTop();
$('#one').css({'opacity':(( 300-scroll )/ 300)+0.4});
$('#two').css({'opacity':(( 600-scroll )/ 300)+0.4});
$('#three').css({'opacity':(( 1100-scroll )/ 300)+0.4});
$('#four').css({'opacity':(( 1400-scroll )/ 300)+0.4});
$('#five').css({'opacity':(( 1700-scroll )/ 300)+0.4});
});
#one{
margin: 2em auto 2em auto;
padding-top: 1em;
height: 300px;
width: 100%;
background-color: coral;
text-align: center;
font-family: sans-serif;
font-size: 2em;
}
#two{
margin: 2em auto 2em auto;
padding-top: 1em;
height: 300px;
width: 100%;
background-color: coral;
text-align: center;
font-family: sans-serif;
font-size: 2em;
}
#three{
margin: 2em auto 2em auto;
padding-top: 1em;
height: 300px;
width: 100%;
background-color: coral;
text-align: center;
font-family: sans-serif;
font-size: 2em;
}
#four{
margin: 2em auto 2em auto;
padding-top: 1em;
height: 300px;
width: 100%;
background-color: coral;
text-align: center;
font-family: sans-serif;
font-size: 2em;
}
#five{
margin: 2em auto 2em auto;
padding-top: 1em;
height: 300px;
width: 100%;
background-color: coral;
text-align: center;
font-family: sans-serif;
font-size: 2em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="one">
first fade element
</div>
<div id="two">
second fade element
</div>
<div id="three">
third fade element
</div>
<div id="four">
fourth fade element
</div>
<div id="five">
fifth fade element
</div>
检查滚动事件内的窗口宽度
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if($(this).width() > 500){ // if window width bigger than 500 change 500 with width you need
$('#one').css({'opacity':(( 300-scroll )/ 300)+0.4});
$('#two').css({'opacity':(( 600-scroll )/ 300)+0.4});
$('#three').css({'opacity':(( 1100-scroll )/ 300)+0.4});
$('#four').css({'opacity':(( 1400-scroll )/ 300)+0.4});
$('#five').css({'opacity':(( 1700-scroll )/ 300)+0.4});
}else{
//if less than 500
}
});
相关文章:
- 在容器中心滚动时淡出
- jQuery淡出后停止自动滚动
- 如何使部分在滚动中淡入淡出
- 试图让我的引导程序navabar背景淡出滚动在我的wordpress主题
- 向上滚动导航栏背景淡出
- 使用CSS不透明度和Javascript在滚动时淡入淡出
- 根据滚动淡入或淡出
- jQuery 在滚动时淡出 - 我做错了什么
- 淡入和淡出在窗口滚动后发生多次
- 网站内容在淡出的标题上滚动
- 当您离开页面底部 100 像素时,淡出“滚动到顶部”按钮
- j查询基于滚动的淡入和淡出
- 淡入和淡出闪烁,如果滚动速度很快
- Jquery滚动淡出
- 修复滚动时延迟的jquery淡入淡出
- 滚动后,尝试在导航栏的背景色中淡入淡出
- 滚动时淡入淡出;不能在移动浏览器中工作
- 更改移动设备上基于滚动的淡入淡出
- 滚动淡入淡出;我不在萤火虫上工作
- jquery fadeTo()滚动时,向下时淡出,但向上时不淡入