简体   繁体   English

不透明度降低脚本不起作用

[英]Opacity reduction script does not working

I have a problem with a script that until recently worked, but now seems not to want to work.我有一个直到最近才工作的脚本有问题,但现在似乎不想工作。 I want to reduce the opacity of the green spheres when scrolling down, it seems to be working until recently, but now I can't figure out what the problem is.我想在向下滚动时降低绿色球体的不透明度,它似乎直到最近才起作用,但现在我无法弄清楚问题是什么。

The website is this: https://attiliosantomo.com/PROVA/该网站是这样的: https ://attiliosantomo.com/PROVA/

The script is this:脚本是这样的:

        $(document).ready(function() {
            $(window).scroll(function(event) {
                let scroll = $(this).scrollTop();
                let opacity = 1 - (scroll / 1300);
                if (opacity > 0.2) {
                    $('.bg-bubble').css('opacity', opacity);
                }
            });
        });
        </script>

Thank you so much for you help非常感谢你的帮助

The issue is that it's not the window that is scrolling.问题是它不是滚动的窗口。 It's the .main-desktop element that is being scrolled.这是正在滚动的.main-desktop元素。 Targeting the scroll event of the .main-desktop as per below should solve the issue.按以下方式定位.main-desktop的滚动事件应该可以解决该问题。

 $(document).ready(function() { // \/ Changed \/ selector from window to '.main-desktop' $('.main-desktop').scroll(function(event) { let scroll = $(this).scrollTop(); let opacity = 1 - (scroll / 1300); if (opacity > 0.2) { $('.bg-bubble').css('opacity', opacity); } }); });
 html, body { height: 100%; margin: 0; } .main-desktop { overflow: scroll; height: 100%; } .inner { height: 3000px; } .bg-bubble { height: 100px; width: 100px; background-color: blue; position: absolute; top: 0; left: 0; border-radius: 50%; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="bg-bubble"></div> <div class="main-desktop"> <div class="inner"></div> </div>

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

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