简体   繁体   中英

Parallax scrolling issue (JQuery)

Using the following plugin , I am building a simple parallax prototype.

So far I got this:

HTML

<div id="one" class="js-background-1 color"> 
    <div class="box">
        <h2>Italian breakfast</h2>
        <p>bla bla</p>
    </div> 
</div>

<div id="two" class="js-background-1 color"> 
    <div class="box">
        <h2>German breakfast</h2>
        <p>bla bla</p>
    </div> 
</div> 

<div id="three" class="js-background-1 color"> 
    <div class="box">
        <h2>Box-2</h2>
        <p>bla bla</p> 
    </div>
</div>   

JS

$(document).ready(function () {

    $('.color').each(function(i) {
        var position = $(this).position(),
            positionSLider = $('.slidingPannel').position();
        $(this).scrollspy({
            min: position.top,
            max: position.top + $(this).height(),
            onEnter: function(element, position) {
                console.log('box sliding in from the right');
            },
            onLeave: function(element, position) {
                console.log('box sliding out');
            }
        });
    });
});

CSS

body{margin:0}

.color{
    z-index:9999;
}

#one{
    background: url(breakfast.jpg) 50% 0 no-repeat fixed;
    color: white;
    height: 1300px;
    margin: 0;
}

#two{
    background: url(http://120dollarsfoodchallenge.files.wordpress.com/2011/02/pancakeshortstack.jpg) 50% 20% no-repeat fixed;
    color: white;
    height: 1300px;
    margin: 0;
    padding: 160px 0 0 0;
}

#three{
    background: url(http://yourstudentbody.com/wp-content/uploads/2013/01/Athlete_-porridge-healthy-breakfast.jpg) 50% 50% no-repeat fixed;
    color: white;
    height: 1300px;
    margin: 0;
    padding: 160px 0 0 0;
}

.color{
    border-top:2px solid #030;
}

h2{
    margin:0;
}

p{
    margin-top:10px;
}

.box{
    width:400px;
    text-align:center;
    background-color:#CCC;
    opacity:0.8;
    margin:12% auto 0;
    color:#000;
    font:arial;
    padding:10px 20px;
}

On the top of this I would like to add a panel sliding from the right for each slide.

So:

  • a new slide comes in
  • the panel from the right slides in
  • the slide disappear together with panel which will slide in with the next slide

An example of what I mean for the right panel is here .

The problem with this is that when I slide to the second one I still have 'console.log('box sliding in from the right');' and this will only disappear until the second slides touches the top.

Is there a way of having the panel from the right be visible a bit before the slides reaches the top?

I would recommend using a JavaScript library such as Skrollr.js.

You will have a great control of your animations and most importantly the timing.

Check our these two tutorials to get you started with Skrollr:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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