简体   繁体   English

滚动显示

[英]Reveal on scroll

I'm trying to make the h1 fade in once visible on scroll 我正在尝试让h1淡入淡出

http://jsfiddle.net/robcleaton/dfggat6b/ http://jsfiddle.net/robcleaton/dfggat6b/

HTML 的HTML

<div class="hero">
    Scroll down
    </div>

<h1 class="animated fadeInUp">Animate fadeIn</h1>

CSS 的CSS

.hero {
    background: green;
    height: 1000px;
}

.animated {
  -webkit-animation-duration: 1s;
          animation-duration: 1s;
  -webkit-animation-fill-mode: both;
          animation-fill-mode: both;
}
.fadeInUp {
  -webkit-animation-name: fadeInUp;
          animation-name: fadeInUp;
}

I don't think there is a way to do this without JavaScript. 我认为如果没有JavaScript,没有办法做到这一点。 If you are using jQuery, you can add a handler to $(window).scroll() that checks to see if your h1 is in viewport and adds the animation class. 如果使用的是jQuery,则可以向$(window).scroll()添加一个处理程序,以检查h1是否在视口中并添加动画类。 You can use the jQuery inViewport plugin to detect if an element is in viewport: http://www.appelsiini.net/projects/viewport 您可以使用jQuery inViewport插件来检测元素是否在视口中: http : //www.appelsiini.net/projects/viewport

I have put some elements around it to make it more clear, but this should do the job. 我在其中添加了一些元素以使其更加清楚,但这应该可以完成工作。

http://jsfiddle.net/chkrmqmx/ http://jsfiddle.net/chkrmqmx/

HTML 的HTML

<div class="hero">
    Scroll down
    </div>

<h1 class="animated fadeInUp" id="fadein">Animate fadeIn</h1>
<div class="hero" id="spacer"></div>

CSS 的CSS

.hero {
    background: green;
    height: 1000px;
}

.animated {
    display: none;
    height: 200px;
}

#spacer {
    margin-top: 200px;
}

Javascript (with jQuery) Javascript(使用jQuery)

$(window).scroll(function() {
    var $this = $(window);

    if ($this.scrollTop() >= 800) {
        $("#spacer").css('margin-top', '0');
        $("#fadein").fadeIn(1000);
    }
});

You can try headroom js. 您可以尝试净空js。 They provide the functionality similar to what you are looking for. 它们提供的功能与您所寻找的相似。 Check out this link -> http://wicky.nillia.ms/headroom.js/ 查看此链接-> http://wicky.nillia.ms/headroom.js/

I've started using this js plugin that seems to cater for all I need 我已经开始使用这个js插件,它似乎可以满足我的所有需求

http://www.jqueryscript.net/demo/jQuery-Plugin-For-Element-Fade-Slide-Effects-As-You-Scroll-FadeThis/ http://www.jqueryscript.net/demo/jQuery-Plugin-For-Element-Fade-Slide-Effects-As-You-Scroll-FadeThis/

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

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