Tagged: CSS
-
AuthorPosts
-
January 25, 2024 at 3:25 pm #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
January 28, 2024 at 5:05 pm #1432271Hey 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,
MikeJanuary 30, 2024 at 1:38 pm #1432497Hello 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
January 31, 2024 at 7:42 am #1432561Hi,
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,
IsmaelJanuary 31, 2024 at 2:57 pm #1432611Hi Ismael,
thanks for your reply. It works on desktop but it doesn’t work on mobile. Do you know why?
Regards,
Kees
February 1, 2024 at 7:11 am #1432669Hi,
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,
IsmaelFebruary 1, 2024 at 8:40 am #1432684Hi 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
February 1, 2024 at 12:03 pm #1432714Hi,
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,
IsmaelFebruary 2, 2024 at 4:21 pm #1432843Hi Ismael,
i provided the link in private, right?
How it is now: https://paste.pics/QBIN6
how it should be: https://paste.pics/QBIN9Thanks in advance.
Regards,
Kees
February 4, 2024 at 2:29 pm #1432926Hi,
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,
MikeFebruary 6, 2024 at 10:50 am #1433200Hi Mike,
this works. Thanks for the help.
Regards,
Kees
February 6, 2024 at 11:43 am #1433220Hi,
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 -
AuthorPosts
- The topic ‘scroll-margin-top & scroll-padding-top css properties’ is closed to new replies.