[Resolved] Can sections already be replaced by GenerateBlocks ?

Home Forums Support [Resolved] Can sections already be replaced by GenerateBlocks ?

Home Forums Support Can sections already be replaced by GenerateBlocks ?

Viewing 16 post (of 16 total)
  • Author
    Posts
  • #1634531
    Rafał

    So nice 😉
    Somewhat universal solution – for image covers, GenerateBlocks with backgrounds, and images with object-fit: cover:

    (function($) {
      $(window).scroll(function() {
        setParalax( $('.PARALLAX-CLASS-HERE') );
      });
      function setParalax( elements ) {
        elements.each(function(i, element) {
          var scrollTop = $(window).scrollTop();
          var viewportHeight = $(window).height();
          var elementHeight = $(this).height();
          var offsetTop = $(this).offset().top;
          var lowerBound = offsetTop - viewportHeight;
          var upperBound = offsetTop + elementHeight;
          var screenScope = (scrollTop - lowerBound) / (upperBound - lowerBound) * 100;
          if( scrollTop > offsetTop - viewportHeight && scrollTop <= upperBound ) {
            // check if element has css background image defined
            if ($(element).css('background-image') != 'none') {
              $(element).css("background-position", "50% " + screenScope + "%");
            }
            // if not, then find image inside
            $(element).find('img').css("object-position", "50% " + screenScope + "%");
          } else {
            if ($(element).css('background-image') != 'none') {
              $(element).css("background-position", "");
            }
            $(element).find('img').removeAttr("style");
          }
        });  
      };
    })(jQuery);
Viewing 16 post (of 16 total)
  • You must be logged in to reply to this topic.