简体   繁体   English

滚动时淡出并向上移动

[英]Fade out and move up while scrolling

The following script I am using fades out the div with the class .fader when scrolling down, it does not fads it out instantly but bit by bit while scrolling. 我正在使用的以下脚本在向下滚动时淡化带有类.fader的div,它不会立即消失,而是在滚动时逐渐消失。

Everything is working, but how can I also make it so the div moves up while the fading effecting is taking place? 一切都在发挥作用,但是我怎样才能让它在衰落效应发生的同时提升?

 //Fade Index on Scroll//
    var divs = $('.fader');
        $(window).on('scroll', function() {
    var st = $(this).scrollTop();
        divs.css({ 'opacity' : (1 - st/300) });
    });

    $(window).scroll(function() {
    if ($(this).scrollTop()>300) {
        $('.fader').fadeOut();
    } else {
        $('.fader').show();
        }
    });

HTML: HTML:

<div id="top-section">
   <div class="content fader">
       <h1>I support and guide you through the process of <span>change</span>, <span>growth</span> and <span>personal evolution</span>.</h1>
   </div>
</div>  

CSS: CSS:

@media screen and (min-width: 1024px) {

        #top-section {
            color: #fff;
            height: 720px; 
            width: 1024px;

            position: relative; 
            padding: 100px 20px;
            margin: auto;
        }

        #top-section .fader {
            width: 400px;
            padding-top: 170px;
            position: fixed;
        }

    }

Live preview: http://www.life-conversations.com/ 实时预览: http//www.life-conversations.com/

Please replace below line ... 请替换下面的行......

$(window).on('scroll', function () {

with

$(window).bind('scroll', function () {

You have to use bind ... 你必须使用bind ...

You can use: 您可以使用:

$(".fader").animate({"opacity":(1 - st/300), "top": "-"+(st/300)},200);

Edit: 编辑:

I don't really understand your desired effect but is this what you want?: 我真的不明白你想要的效果,但这是你想要的吗?:

$(".fader").animate({"opacity":(1 - st/300), "top": "-"+st},50);

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

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