-
AuthorPosts
-
August 31, 2022 at 6:17 pm #1363394
Hi,
would it be possible to set a common height of the slides on the content slider?
Thanks a lot.September 1, 2022 at 8:46 am #1363446Hey neon2020,
Thank you for the inquiry.
The script below should apply the height of the tallest slide to every slides in the content slider. You can place it in the functions.php file.
// custom script: set min height to slider function ava_custom_script_set_min_height() { ?> <script type="text/javascript"> (function($) { $(document).ready(function() { // Get an array of all element heights function setSlideHeight(element) { var elementHeights = element.map(function() { return $(this).height(); }).get(); // Math.max takes a variable number of arguments // <code>apply</code> is equivalent to passing each height as an argument var maxHeight = Math.max.apply(null, elementHeights); // Set each height to the max height element.height(maxHeight); } $(window).on( 'debouncedresize', function() { var slider = $('.avia-content-slider-inner'); var slides = slider.find('.slide-entry-wrap'); setSlideHeight(slides); }); }); })(jQuery); </script> <?php } add_action( 'wp_footer', 'ava_custom_script_set_min_height', 9999 );
Based on: https://stackoverflow.com/questions/6781031/use-jquery-css-to-find-the-tallest-of-all-elements
Best regards,
IsmaelSeptember 1, 2022 at 10:40 pm #1363545Thank you Ismael. I’ve pasted the code in the functions.php file but it didn’t work. (so I restored the old version of the file).
Is there something else I can do?
(or is there a way to set the shape of the slides as squares, all with the same dimensions?)- This reply was modified 2 years, 2 months ago by neon2020.
September 2, 2022 at 8:57 am #1363579Hi!
Thank you for the update.
Did you purge the cache after adding the script? We may need to access the site in order to test the modification properly. Please provide the login details in the private field.
Regards,
IsmaelSeptember 2, 2022 at 10:01 am #1363593Thanks. Please find here below the access.
The page with content slider is https://www.neon-pro.it/nuova-home-2022- This reply was modified 2 years, 2 months ago by neon2020.
September 3, 2022 at 8:00 am #1363708I’ve tried again, uploading the functions.php file and deleting the browser cache, but still it doesn’t work.
September 4, 2022 at 7:51 pm #1363826Hi,
Thanks for the link to your page and the login, I added a custom class to your content slider equal-height-slider on your /nuova-home-2022/ page so there won’t be any conflicts with other content sliders on your site.
Then I adjusted the script a little and added it to your child theme functions.php:
function ava_custom_script_set_min_height() { ?> <script type="text/javascript"> window.addEventListener('DOMContentLoaded', function() { (function($) { function setSlideHeight(element) { var elementHeights = element.map(function() { return $(this).height(); }).get(); var maxHeight = Math.max.apply(null, elementHeights); element.height(maxHeight); } $(window).on( 'debouncedresize', function() { var slider = $('.equal-height-slider .slide-entry-wrap'); var slides = slider.find('.slide-entry-excerpt'); setSlideHeight(slides); }); })(jQuery); }); </script> <?php } add_action( 'wp_footer', 'ava_custom_script_set_min_height', 9999 );
Now it is working:
compared to before:
Please clear your browser cache and check.Best regards,
MikeSeptember 5, 2022 at 12:26 am #1363862Fantastic!!! Thank you very much!!!
It works perfectly.September 5, 2022 at 12:51 pm #1363906Hi,
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 ‘Content slider: common height’ is closed to new replies.