Tagged: snap scroll
-
AuthorPosts
-
February 8, 2023 at 1:34 pm #1397172
Dear Kriesi Team,
i tried a few things but the Snap Scroll JQUERY does not work on my website.
The snap-scroll.js is loading in the header and the div sections have the right class but it’s not working.Maybe you got a solution?
The link is in the private content.Thanks in advance and best regards!
JasperFebruary 9, 2023 at 5:07 am #1397259Hey Jasper_1,
Thank you for the inquiry.
How did you load or initialize the script? Did you use the wp_enqueue_script function?
// https://developer.wordpress.org/reference/functions/wp_enqueue_script/
Best regards,
IsmaelFebruary 9, 2023 at 10:23 am #1397282Hi Ismael,
thank yo for the quick response.I use a child theme and the script is loaded in the functions.php like this:
// Register and enqueue scripts
function my_custom_scripts() {
wp_enqueue_script(
‘custom-script’,
get_stylesheet_directory_uri() . ‘/js/snap-scroll.js’,
array( ‘jquery’ )
);
}add_action( ‘wp_enqueue_scripts’, ‘my_custom_scripts’ );
Best regards,
JasperFebruary 10, 2023 at 5:58 am #1397382Hi,
We are not familiar with the script unfortunately, and we are not really sure what it does. How did you initialize it? Would you mind providing a link to the documentation?
Best regards,
IsmaelFebruary 10, 2023 at 10:32 am #1397422Hi,
sorry, i’m not that good with JS. Here is the documentation: https://www.jqueryscript.net/animation/Snap-To-Section-SnapScroll.html
I use a Codeblock for the call, maybe there is the error:
<script>
var snapScroll = $(“.av-layout-grid-container”).SnapScroll({
hashes:true
});
console.log(snapScroll);
</script>Could you help me please?
And i was wondering why there isn’t a Scroll Snap function in the theme. There are a few posts about it in the forum.
I also tried the CSS way with “scroll-snap-type” and “scroll-snap-align”, but it won’t work either, why?Best regards,
JasperFebruary 10, 2023 at 6:19 pm #1397493Hi,
Thanks for the link to your site, I see you are getting this error:Uncaught TypeError: $ is not a function
this is because the code you added to the code block is this:<script> var snapScroll = $(".av-layout-grid-container").SnapScroll({ hashes: true }); console.log(snapScroll); </script>
the problem is that your script needs to be wrapped like this:
<script> (function($){ var snapScroll = $(".av-layout-grid-container").SnapScroll({ hashes: true }); console.log(snapScroll); })(jQuery); </script>
this should solve the error, if you are forcing jQuery into your footer try this:
<script> window.addEventListener('DOMContentLoaded', function() { (function($){ var snapScroll = $(".av-layout-grid-container").SnapScroll({ hashes: true }); console.log(snapScroll); })(jQuery); }); </script>
If this doesn’t correct please include admin login in the Private Content area so we can investigate.
Best regards,
MikeFebruary 13, 2023 at 5:11 pm #1397780Hi,
thank you so much, it works fine in the footer.Now i have another problem. To work properly, the elements has to be full height of the browser (100vh).
That works fine on desktop view but on mobile devices the content will cut off.
Do you have any idea, how i can work around that problem?Thank you very much!
Best regards,
JasperFebruary 13, 2023 at 7:11 pm #1397805Hi,
Glad to hear this helped, for mobile it looks like you are overriding the 100vh with 100%!important:@media only screen and (max-width: 480px){ .av-layout-grid-container { height: 100% !important; } }
I recommend using 100vh;
and for the inner container you are adding: height: auto !important;media only screen and (max-width: 767px){ .responsive #top #wrap_all .av-flex-cells .no_margin { display: block; margin: 0; height: auto !important; overflow: hidden; float: left; clear: none; width: 100%; } }
I recommend setting the height to 50vh like this:
@media only screen and (max-width: 767px) { .responsive #top #wrap_all #main .av-flex-cells .no_margin { height: 50vh !important; } }
and changing the top padding for mobile to 20px from the current 70px, this looks like the text will then fully show, you could also tweak the font size a little or change the image height a little to allow more room for the text.
Best regards,
MikeFebruary 13, 2023 at 9:26 pm #1397822Hi,
thanks again for your quick help!With the changes and tweaking it almost works out but its a very limited user experience.
Is there a way to leave the script out off mobile view?
I’ve tested a few things but none of it worked?Thank you an best regards,
JasperFebruary 14, 2023 at 1:43 pm #1397912Hi,
Try changing your code block script to this to only allow it to run on screens above 767px:<script> window.addEventListener('DOMContentLoaded', function() { (function($){ var width = $(window).width(); if (width >= 767) { var snapScroll = $(".av-layout-grid-container").SnapScroll({ hashes: true }); console.log(snapScroll); } })(jQuery); }); </script>
If you test with Dev Tools you must reload the page when emulating a mobile device, this will work correctly on actual devices.
Best regards,
MikeFebruary 16, 2023 at 8:56 pm #1398263Thank you very much! :-)
February 16, 2023 at 9:13 pm #1398267Hi,
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 ‘Snap Scroll does not work’ is closed to new replies.