Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript CSS transitions and Javascript

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #208606
    kamaboko
    Participant

    Hello,

    I’m using JS to have a text box come out from the right side when one scrolls down the page. I can’t seem to figure out the correct syntax though to have the background color of the text box fade in.

    Help much appreciated.

    http://codepen.io/kamaboko/pen/EVgQwJ

    #208669
    Mottie
    Member

    Paulie, that demo makes the popout start and stop continuously while scrolling down. I ended up modifying the code a bit:

    var setPoint = .7, // .7 = 70% scroll height
        isVisible = false,
        win = document.getElementById('popOut'),
        height = document.body.scrollHeight - window.innerHeight;
    
    function scroller() {
      var loc = document.body.scrollTop / height;
      if ( loc >= setPoint && !isVisible ) {
        win.classList.add( 'showing' );
        isVisible = true;
      } else if ( loc < setPoint && isVisible) {
        win.classList.remove( 'showing' );
        isVisible = false;
      }
    }
    
    window.onscroll = scroller;
    

    With the changes above, you can set a percentage height of total where the popout becomes visible instead of picking an arbitrary value.

    http://codepen.io/Mottie/pen/xwEMYo

    #208688
    kamaboko
    Participant

    Hi Mottie,

    Thanks for your reply and code post. It made me think about this type of solution in a different way.

    Cheers,
    K

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.