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

    Dear Enfold Support

    As suggested by Enfold’s support member Ismael, I open this separate topic about a issue I mentioned firstly on another thread: https://kriesi.at/support/topic/toggles-of-accordions-are-covered-by-the-sticky-header/

    I have an accordion with the toggle’s mode “one toggle open at a time”. If I open the first toggle of an accordion on bigger screens (desktop view) and scroll down to the second toggle and open it, the first toggle closes and the document scrolls to the top of the second toggle but the toggle is covered by the sticky header.

    See link to webpage with the accordion in Private Content.

    Ismael provided the following solution:

    To fix the issue with the toggles and make sure that the toggle title is visible on click, we edited the enfold/config-templatebuilder/avia-shortcodes/toggles/toggles.js file around line 47 and adjusted the scoll_target value.

    //check if toggle title is in viewport. if not scroll up
    				    var el_offset = content.offset().top,
    				        scoll_target = el_offset - 50 - parseInt($('html').css('margin-top'),10);
    				    
    				        $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - 100},200);
    				}
    

    That solution works well and the toggles aren’t covered by the sticky header anymore. But the offset (100px) is now the same on desktop and mobile view. Is it possible to have a different offset value on mobile view when the header isn’t sticky?
    The code needs to be completed with a dependency of the screen width. For example, if the screen width is 768px or more (header is sticky) then the offset is 100px and if the screen width is less than 768px (header isn’t sticky) then the offset is 10px. How can this be achieved?

    Kind regards
    Ueli

    #1352720

    Hey Ueli,

    Thank you for opening a new thread.

    Please look for this line in the code that we modified above..

     $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - 100},200);
    

    .. and replace it with the following code.

     $scoll_target_offset = wp_is_mobile() ? 10 : 100;
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - $scoll_target_offset},200);
    

    Please make sure toggle or temporarily disable the Enfold > Performance > File Compression settings after adding the css.

    Best regards,
    Ismael

    #1353138

    Hi Ismael

    The new code doesn’t work. I can open and close a toggle once but then no toggle can be opened again. Please see Link in Private Content.

    Kind regards
    Ueli

    #1353403

    Hi,

    Sorry about that. For some reason, I integrated a WordPress function in a Javascript file, must have been confused for a moment. Please look for the same line, then replace it with the following code.

    $scoll_target_offset = 100;
    
    if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
        $scoll_target_offset = 10;
    }
    
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - $scoll_target_offset},200);
    

    Please make sure to toggle or temporarily disable the Enfold > Performance > File Compression settings after modifying the file.

    Thank you for your patience.

    Best regards,
    Ismael

    #1353514

    Hi Ismael

    Your new code…

     //check if toggle title is in viewport. if not scroll up
    	var el_offset = content.offset().top,
    	scoll_target = el_offset - 50 - parseInt($('html').css('margin-top'),10);
    	$scoll_target_offset = 100;
    
    if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
       	$scoll_target_offset = 10;
    }
    
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - $scoll_target_offset},200);
    }

    … doesn’t work either.

    And how reliable is your approach of device detection?
    Wouldn’t it be easier to make the code dependent of the screen width – as I’ve written in my initial post – because the header isn’t sticky if the screen width is less than 768px, regardless of the device?

    We know that the code mentioned in my initial post is doing well with a sticky header.
    Couldn’t we change the line…

    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - 100},200);
    

    …to something like that?

    if ($(window).width() < 768) {				    
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - 10},200);
    } else {
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - 100},200);
    				}

    Before, shouldn’t there be a declaration of the variable var width = $(window).width()? But I don’t know where exactly.

    Kind regards
    Ueli

    #1353554

    Hi,

    …to something like that?

    Yes, that should work. Try to replace the line with:

    
    $scoll_target_offset = $(window).width() < 768 ? 10 : 100;
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - $scoll_target_offset},200);
    

    Please make sure to toggle or temporarily disable the Enfold > Performance > File Compression settings after adding the script.

    Thank you for your patience.

    Best regards,
    Ismael

    #1353569

    Hi Ismael
    The code looks now like this…

     //check if toggle title is in viewport. if not scroll up
    				    var el_offset = content.offset().top,
    				        scoll_target = el_offset - 50 - parseInt($('html').css('margin-top'),10);
    				    
    				        $scoll_target_offset = $(window).width() < 768 ? 10 : 100;
    $('html:not(:animated),body:not(:animated)').animate({scrollTop: scoll_target - $scoll_target_offset},200);

    …but it doesn’t work. I can open and close one toggle but no other toggle can be opened.
    Kind regards
    Ueli

    #1353681

    Hi,

    Sorry about that. We forgot to initialize the $scoll_target_offset. Please look for this line..

    $scoll_target_offset = $(window).width() < 768 ? 10 : 100;
    

    .. and replace it with:

    var $scoll_target_offset = $(window).width() < 768 ? 10 : 100;
    

    This should remove this error.

    Uncaught ReferenceError: $scoll_target_offset is not defined
    

    Best regards,
    Ismael

    #1354065

    Hi Ismael

    The code is working now quite well.

    But there is a new issue with the first toggle “Schulen und Gruppen im Lager”. The long title gets a line break on small screens (less than 447px) what makes the toggle higher. As a result, the toggle isn’t completely visible when I open it. It’s partially cut by the upper screen border. All other toggles stay completely visible when activated. Why does this happen? Isn’t the upper border of a toggle the reference point of the offset?

    I realize, that the whole concept of the accordion’s mode “one toggle open at a time” in combination with a sticky header stays very tricky.

    Kind regards
    Ueli

    #1354093

    Hi,

    The long title gets a line break on small screens (less than 447px) what makes the toggle higher

    But the toggle is visible? Unfortunately, the script doesn’t take the height of the toggle title into account. You may need to hire a freelance developer if you need to further adjust the script and make it consider or calculate every related elements in the page.

    Best regards,
    Ismael

    #1354968

    Hi Ismael

    Right now, I can live with the current state. It might be a claim or a goal for Enfold‘s developers to bring the accordion‘s behavior to perfection in a future update.

    Thank you very much for your help and your patience with a picky customer.

    Kind regards
    Ueli

    #1354999

    Hi,
    Glad Ismael could 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 ‘Different scroll offset of toggles on desktop and mobile view’ is closed to new replies.