简体   繁体   English

更改Navbar-logo onScroll的不透明度

[英]Change Opacity of Navbar-logo onScroll

I want to create a navbar that changes the opacity of the logo in it onscroll over 50px, i have made some code in JS but it is not working, i have also made the animation in anime.js, the animation works but will not trigger on 50px, can you help? 我想创建一个导航栏,将其滚动的徽标的不透明度更改为超过50像素,我已经在JS中编写了一些代码,但是它不起作用,我也在anime.js中制作了动画,该动画有效但不会触发在50px上,您能帮忙吗?

 //animation in animejs var LogoScroll = anime({ targets: '.Logo', autoplay: false, opacity: 0, duration: 400, easing: 'cubicBezier(.75,.09,.65,.84)', }); // code that doesn't work window.onscroll = function LogoChange() { var scroll = window.scrollTop; if (scroll > 100) { LogoScroll.play(); } else { LogoScroll.reverse(); } } 

Try this code. 试试这个代码。

I have implemented using jQuery. 我已经使用jQuery实现了。

 $(window).scroll(function () {
      var scroll = $(window).scrollTop();
       if (scroll > 100) { 
             LogoScroll.play(); 
       } else {
             LogoScroll.reverse(); 
      } });

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

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