Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1432031

    Hello,

    how can I get the scroll-margin-top & scroll-padding-top css properties to work with the enfold theme?
    I tried removing overflow: hidden; properties from parent containers, disabled as much css as possible but no way I can get it working.

    Thanks in advance for your reply.

    Regards,

    Kees

    #1432271

    Hey keeslamper,
    According to the Scroll Snap Model you need to use the scroll-snap-type property and the overflow needs to be scroll. I’m not very familiar with all of the settings for the elements or the parent elements, it is not used in the theme, but this article may help.
    A few points that I found is that scroll-snap will not work with a fixed header and the scroll-snap-type & overflow needs to be on the html like this:

    html {
      scroll-snap-type: y mandatory;
      overflow-y: scroll;
      scroll-behavior: smooth;
    }
    #main > div {
      scroll-margin-top: 30px;
      scroll-snap-align: start none;
    }

    But I believe that the smooth scroll js interfere with this css. I have ask the rest of the team for advise, Thank you for your patience.

    Best regards,
    Mike

    #1432497

    Hello Mike,

    thanks for your reply.
    I don’t want scroll snapping in this case. I use anchortags on a page which scroll to an id on the page (like: text). Because of the sticky header, the header overlaps the content it scrolls to.
    One line of css (scroll-margin-top) could be enough to solve this problem, but I think something in the theme prevents it.
    You can see an article how it works here. I use it more often on other websites but can’t get it to work in enfold.

    Regards,

    Kees

    #1432561

    Hi,

    Thank you for the info.

    It might not be working because of the AviaScrollSpy script which handles scrolling for anchor links and overrides the default scrolling behavior. Instead of using the scroll-margin-top, try to add the following filter in the functions.php file.

    function avf_header_setting_filter_mod($header) {
    	$header['header_scroll_offset'] = $header['header_scroll_offset'] + 100;
    	return $header;
    }
    add_filter('avf_header_setting_filter', 'avf_header_setting_filter_mod', 9999, 1);
    

    This will add a 100px offset from the original scroll position.

    Best regards,
    Ismael

    #1432611

    Hi Ismael,

    thanks for your reply. It works on desktop but it doesn’t work on mobile. Do you know why?

    Regards,

    Kees

    #1432669

    Hi,

    The filter should also work on mobile view. Have you tried purging the cache and doing a hard refresh? Please try to set a bigger offset for testing.

    Best regards,
    Ismael

    #1432684

    Hi Ismael,

    does this only work with a sticky header? Because on mobile the header is not sticky, But i have another sticky element on the page which covers the content.
    There’s currently no cache on the page + I tried a higher offset already. I added the url to the page in private box.

    Regards,

    Roy

    #1432714

    Hi,

    The script runs on mobile view but looks like it doesn’t apply the offset. Would you mind providing a screenshot of where the anchor lands on mobile view?

    Thank you for your patience.

    Best regards,
    Ismael

    #1432843

    Hi Ismael,

    i provided the link in private, right?

    How it is now: https://paste.pics/QBIN6
    how it should be: https://paste.pics/QBIN9

    Thanks in advance.

    Regards,

    Kees

    #1432926

    Hi,
    For mobile try this slow scroll to anchor with offset function in your child theme functions.php, I tested in on your page by injecting it in the browser and it seemed to work well.

    function slow_scroll_to_anchor_with_offset() { ?>
      <script>
    (function($) {
    	var width = $(window).width();
        if ((width <= 767)) {
      $('a[href*=#]:not([href=#])').click(function() {
        if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
    && location.hostname == this.hostname) {
    
          var target = $(this.hash);
          target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top - 80 //offset
            }, 1000);
            return false;
          }
        }
      });
      //Executed on page load with URL containing an anchor tag.
      if($(location.href.split("#")[1])) {
          var target = $('#'+location.href.split("#")[1]);
          if (target.length) {
            $('html,body').animate({
              scrollTop: target.offset().top - 80 //offset
            }, 1000);
            return false;
          }
        }
        } else {}
    }(jQuery));
    </script>
      <?php
    }
    add_action( 'wp_footer', 'slow_scroll_to_anchor_with_offset', 99 );

    Best regards,
    Mike

    #1433200

    Hi Mike,

    this works. Thanks for the help.

    Regards,

    Kees

    #1433220

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘scroll-margin-top & scroll-padding-top css properties’ is closed to new replies.