scrollreveal icon indicating copy to clipboard operation
scrollreveal copied to clipboard

'reveal' all animations without need to scroll?

Open dtate888 opened this issue 10 years ago • 2 comments

feature request I know that scrolling is in the name, but in actuality we just want the animations to appear in a sequence on page load, even if it manages to be (just outside of) the viewport. I guess this might be a duplicate of #215 . Basically, I'm just using scrollreveal as an effects library, and I want to be able to 'trigger' the effect.

dtate888 avatar Feb 06 '16 02:02 dtate888

Hi @dtate888

It’s actually an exact duplicate of #145 :wink: but thank you for looking before opening an issue. The solution is very straight forward, the element should be considered visible no matter where it is.

All that is needed is to update the source so that our _isElemVisible method goes from all this biz...

function _isElemVisible( elem ){
  var offset     = _getOffset( elem.domEl );
  var container  = _getContainer( elem.config.container );
  var scrolled   = _getScrolled( elem.config.container );
  var vF         = elem.config.viewFactor;
  // Define the element geometry.
  var elemHeight = offset.height;
  var elemWidth  = offset.width;
  var elemTop    = offset.top;
  var elemLeft   = offset.left;
  var elemBottom = elemTop  + elemHeight;
  var elemRight  = elemLeft + elemWidth;

  return ( confirmBounds() || isPositionFixed() );

  function confirmBounds(){
    // Define the element functional boundaries, including the viewFactor.
    var top        = elemTop    + elemHeight * vF;
    var left       = elemLeft   + elemWidth  * vF;
    var bottom     = elemBottom - elemHeight * vF;
    var right      = elemRight  - elemWidth  * vF;
    // Define the container boundaries.
    var viewTop    = scrolled.y + elem.config.viewOffset.top;
    var viewLeft   = scrolled.x + elem.config.viewOffset.left;
    var viewBottom = scrolled.y - elem.config.viewOffset.bottom + container.height;
    var viewRight  = scrolled.x - elem.config.viewOffset.right  + container.width;
    // Check if our element is within bounds.
    return ( top    < viewBottom )
        && ( bottom > viewTop    )
        && ( left   > viewLeft   )
        && ( right  < viewRight  );
  }

  function isPositionFixed(){
    return ( window.getComputedStyle( elem.domEl ).position === 'fixed' );
  }
}

To this biz...

function _isElemVisible( elem ){
  return true;
}

Good luck! :bow:

jlmakes avatar Feb 06 '16 12:02 jlmakes

You rock sir!

dtate888 avatar Feb 06 '16 20:02 dtate888