【问题标题】:How do i fadeIn a grid of images on scroll in jQuery?我如何在 jQuery 中滚动滚动图像网格?
【发布时间】:2014-08-15 02:49:03
【问题描述】:

我有一个图像网格,当图像通过 JQuery 淡入滚动显示时,我想淡入,这是我当前的代码,JS Fiddle code

我已尝试使用此代码,但无法正常工作。

jQuery

$(document).ready(function() {

    $(window).scroll( function(){

        $(".vw").each( function(i){

            var bottom_of_object = $(this).position().top + $(this).outerHeight();
            var bottom_of_window = $(window).scrollTop() + $(window).height();

            if( bottom_of_window > bottom_of_object ){

                $(this).animate({'opacity':'1'},500);

            }

        }); 

    });

});

HTML

<div id="grid">
    <div class="vw">
        <img src="http://th08.deviantart.net/fs71/200H/i/2012/190/b/7/bastique_graffiti_art_car__02__golf_mkv_r32_by_bastiqueart-d56k7iu.jpg" width="300" height="169" />
    </div>
    <div class="vw">
        <img src="http://th08.deviantart.net/fs71/200H/i/2012/190/b/7/bastique_graffiti_art_car__02__golf_mkv_r32_by_bastiqueart-d56k7iu.jpg" width="300" height="169" />
    </div>
    <div class="vw">
        <img src="http://th08.deviantart.net/fs71/200H/i/2012/190/b/7/bastique_graffiti_art_car__02__golf_mkv_r32_by_bastiqueart-d56k7iu.jpg" width="300" height="169" />
    </div>
    <div class="vw">
        <img src="http://th08.deviantart.net/fs71/200H/i/2012/190/b/7/bastique_graffiti_art_car__02__golf_mkv_r32_by_bastiqueart-d56k7iu.jpg" width="300" height="169" />
    </div>
    <div class="vw">
        <img src="http://th08.deviantart.net/fs71/200H/i/2012/190/b/7/bastique_graffiti_art_car__02__golf_mkv_r32_by_bastiqueart-d56k7iu.jpg" width="300" height="169" />
    </div>
    <div class="vw">
        <img src="http://th08.deviantart.net/fs71/200H/i/2012/190/b/7/bastique_graffiti_art_car__02__golf_mkv_r32_by_bastiqueart-d56k7iu.jpg" width="300" height="169" />
    </div>
</div>

CSS

  .vw {
        position: relative;
        float:left;
        padding:0px 0px 0px 0px;
        width:300px;
        height:169px;
    }
    #grid {
        margin: 0 auto;
        background-color:green;
        width:900px;
        height:2366px;
    }

【问题讨论】:

标签: jquery css jquery-animate


【解决方案1】:

试试 jquery.appear 插件:http://morr.github.io/appear.html

它添加了一个您可以绑定到的 appear 事件。

<div id='scrollOver'>This might be lower on the page</div>
$('#scollOver').appear();
$('#scrollOver').on('appear', function(event, $all_appeared_elements) {
  // this element is now inside browser viewport
  alert('Now visible!');
});

编辑:这里有一个小提琴供你尝试:http://jsfiddle.net/nzt5hqd2/

【讨论】:

  • 您是否在控制台中看到错误?您是否正确包含了 JS 库?我需要更多信息来帮助您解决问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-30
  • 1970-01-01
  • 2020-09-09
  • 2015-02-20
  • 2013-09-01
相关资源
最近更新 更多