Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1363394

    Hi,
    would it be possible to set a common height of the slides on the content slider?
    Thanks a lot.

    #1363446

    Hey 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,
    Ismael

    #1363545

    Thank 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, 3 months ago by neon2020.
    #1363579

    Hi!

    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,
    Ismael

    #1363593

    Thanks. 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, 3 months ago by neon2020.
    #1363708

    I’ve tried again, uploading the functions.php file and deleting the browser cache, but still it doesn’t work.

    #1363826

    Hi,
    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.
    2022-09-04_017.jpg
    Then I adjusted the script a little and added it to your child theme functions.php:
    2022-09-04_018.jpg

    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:
    2022-09-04_019.jpg
    compared to before:
    2022-09-04_015.jpg
    Please clear your browser cache and check.

    Best regards,
    Mike

    #1363862

    Fantastic!!! Thank you very much!!!
    It works perfectly.

    #1363906

    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 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Content slider: common height’ is closed to new replies.