使用航点逐个淡入多个div(包括图像)

时间:2013-05-30 01:44:15

标签: jquery html jquery-waypoints

基本上,我在这里要做的是当用户滚动到页面底部时逐个淡入3 div。

我在线搜索并发现这可以通过使用名为waypoints的jquery插件来完成。但是,我在Jquery是全新的,我真的无法弄清楚如何做到这一点。

如果有人可以亲切地查看我的代码并告诉我我做错了什么,那将非常有用!

这是HTML:

    <!--#Div1-->
    <div class="span4" id="fadein1" style="display:none">
    <img src="images/41.jpg" alt="41%" style="margin-right: 10px;" id="41">
        <h2>Boba</h2> 
        <p>We strive for <b>perfection</b> when we prepare our boba 
to use. Not under, nor overcooked to mush. Just right and still chewy.</p>

    </div><!-- /.span4 -->
        <div class="span4" id="fadein2" style= "display:none;">
        <img src="images/43.jpg" alt="43%" style="" id="43">
          <h2>Tea Leaves</h2>
          <p>Tea Powders? <b>NEVER!</b> Premixes? <b>Absolutely not!</b> 
We use only the best quality house blend tea leaves.</p>

    </div><!-- /.span4 -->    

    <div class="span4" id="fadein3" style="display:none;">
          <img src="images/44.jpg" alt="44%" style="" id="44">
          <h2>Customized Blend</h2>
          <p>It is our goal to customize your drink the way 
<b>you</b> want it to be. 75% sugar? Light ice? You name 
it, and we will make it happen!</p>

    </div><!-- /.span4 -->

这是JS

$(document).ready(function() {

    // call waypoint plugin
    $("#fadin1").waypoint( function( bottom-in-view ) {
        $(this).fadein(1500);
   }, {
        offset: 'bottom-in-view'
   }

   $("#fadin2").waypoint( function( bottom-in-view ) {
        $(this).fadein(2000);
   }, {
        offset: 'bottom-in-view'
   }

   $("#fadin3").waypoint( function( bottom-in-view ) {
        $(this).fadein(2500);
   }, {
        offset: 'bottom-in-view'
   }
);

1 个答案:

答案 0 :(得分:0)

试试这个脚本。滚动到达他们的div时,你的div会褪色。

我认为你应该在这些隐藏的div的顶部和底部有一些内容。

$(document).ready(function() {
$('#fadein1').waypoint(function(event, direction) {
    $(this).fadeIn(1500);
}, {
    offset: function() {
       return -$(this).height();
    }
});

$('#fadein2').waypoint(function(event, direction) {
    $(this).fadeIn(2000);
}, {
    offset: function() {
       return -$(this).height();
    }
});

$('#fadein3').waypoint(function(event, direction) {
    $(this).fadeIn(2500);
}, {
    offset: function() {
       return -$(this).height();
    }
});
});

HTML应该像......

<div>Top content 1</div>
<div>Top content 1</div>

<div>Your hidden div 1</div>
<div>Your hidden div 2</div>
<div>Your hidden div 3</div>

<div>Below content 1</div>
相关问题