简体   繁体   English

jQuery淡入和淡出滚动在iOS上无法正常工作

[英]JQuery Fade in and fade out on scroll not working properly on iOS

I have the following code that fades a button in fixed to the bottom as the user scrolls and fades out when the user scrolls to the top on mobile... works fine when tested in responsive mode on desktop, however on iOS it snaps on after a moments delay but fades out when scrolling back to the top as it should, how can I stop it from snapping on? 我有以下代码,当用户滚动时,按钮固定在底部,当用户滚动到移动设备顶部时,按钮逐渐淡出...在桌面上的响应模式下进行测试时,效果很好,但是在iOS上,稍有延迟,但在按原样滚动回顶部时会淡出,如何阻止它突然弹起?

CSS CSS

.cta {
    background-color: rgba(75, 113, 252, 0.9);
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    text-align: center;
    line-height: 50px;
    color: #fff;
    height: 50px;
    width: 100%;
    opacity: 1;
    z-index: 999;
 }

js JS

$(window).scroll(function() {
if ($(this).scrollTop()> 150) {
$('.cta').fadeIn();
} else {
$('.cta').fadeOut();
}
});

Have you tried different methods of lazy loading? 您是否尝试过不同的延迟加载方法? I've had success with this plug-in in the past: https://github.com/tuupola/jquery_lazyload 我过去在此插件上取得过成功: https//github.com/tuupola/jquery_lazyload

It's not particularly complicated. 它并不特别复杂。 Here's a quick example: 这是一个简单的示例:

HTML: HTML:

<img class="example" data-original="img/myImage.jpg">

JS: JS:

$("img.example").lazyload();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM