[英]jQuery fade in / fade out animation
Well I have a problem that I don't really know how to solve. 好吧,我有一个问题,我真的不知道如何解决。 I'm new to jQuery and JavaScript.
我是jQuery和JavaScript的新手。 I use jQuery to animate a text.
我使用jQuery来动画文本。
My problem is that I want to make an object fade out/in when scrolled out of view. 我的问题是我想在滚出视图时使对象淡出/淡出。 Opacity of the element changes but I'm not sure how to "zoom" it in at the same time...
元素的不透明度发生了变化,但我不确定如何同时“缩放”它...
I would want to do this in the way which will allow me to use a standard css transform. 我希望以允许我使用标准css转换的方式执行此操作。
$(window).scroll(function() { $(".top").css("opacity", 1 - $(window).scrollTop() / 150); });
* { padding: 0; margin: 0; } .header1 { width: 100%; background-image: url(https://simply-design.ml/img/start1.jpg); background-size: cover; display: flex; justify-content: center; align-items: center; padding-top: 60px; } .header-sec { width: 75%; margin: 25px 0px; padding: 30px 0px; } .header-sec h1 { font-size: 75px; font-family: arial; } .header-sec .p1 { font-size: 27px; font-family: arial; } .space { background-color: #fff; height: 300px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <header class="header1"> <section class="header-sec"> <center class="top"> <h1>TITLE</h1> <div style="height: 3px; width: 100px; background-color: #000; margin: 30px;"></div> <p class="p1">subtitle here</p> </center> </section> </header> <section class="space"></section>
Use scale property of transform like this 像这样使用变换的scale属性
var abc = 1 - $(window).scrollTop() / 150;
$(".top").css("opacity", abc);
$(".top").css("transform", "scale(" + abc + ")");
* { padding: 0; margin: 0; } .header1 { width: 100%; background-image: url(https://simply-design.ml/img/start1.jpg); background-size: cover; display: flex; justify-content: center; align-items: center; padding-top: 60px; } .header-sec { width: 75%; margin: 25px 0px; padding: 30px 0px; } .header-sec h1 { font-size: 75px; font-family: arial; } .header-sec .p1 { font-size: 27px; font-family: arial; } .space { background-color: #fff; height: 300px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <header class="header1"> <section class="header-sec"> <center class="top"> <h1>TITLE</h1> <div style="height: 3px; width: 100px; background-color: #000; margin: 30px;"></div> <p class="p1">subtitle here</p> </center> </section> </header> <section class="space"></section> <script> $(window).scroll(function() { var abc = 1 - $(window).scrollTop() / 150; $(".top").css("opacity", abc); $(".top").css("transform", "scale(" + abc + ")"); }); </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.