-
AuthorPosts
-
May 22, 2022 at 6:32 pm #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
UeliMay 24, 2022 at 7:43 am #1352720Hey 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,
IsmaelMay 27, 2022 at 12:44 pm #1353138Hi 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
UeliMay 30, 2022 at 4:47 am #1353403Hi,
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,
IsmaelMay 31, 2022 at 12:53 am #1353514Hi 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
UeliMay 31, 2022 at 9:35 am #1353554Hi,
…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,
IsmaelMay 31, 2022 at 11:44 am #1353569Hi 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
UeliJune 1, 2022 at 6:02 am #1353681Hi,
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,
IsmaelJune 3, 2022 at 6:40 pm #1354065Hi 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
UeliJune 4, 2022 at 3:16 am #1354093Hi,
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,
IsmaelJune 12, 2022 at 1:45 pm #1354968Hi 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
UeliJune 12, 2022 at 10:44 pm #1354999Hi,
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 -
AuthorPosts
- The topic ‘Different scroll offset of toggles on desktop and mobile view’ is closed to new replies.