Tagged: link to accordion
-
AuthorPosts
-
April 10, 2023 at 6:53 pm #1404057
Hello,
Any link to an accordion’s tab scrolls the page so that the tab title becomes invisible. I use custom tab and toggle ID’s, but with the default ones it was the same. Please click the first “Comparing WPML” link on the page from the private content to see the issue.
Regards,
MarinaApril 13, 2023 at 3:13 am #1404297Hey Marina,
Thanks for your patience and the link to your site, Try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:function anchor_offset_with_slow_scroll() { ?> <script> (function($) { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top - 100 //offsets for fixed header }, 1000); return false; } } }); }(jQuery)); </script> <?php } add_action('wp_footer', 'anchor_offset_with_slow_scroll');
Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
Best regards,
MikeApril 13, 2023 at 5:38 pm #1404376Hi Mike,
Thank you for the code, it works. There is only one issue: it added an offset for all the anchors. Is it possible to apply the offset only for links to accordion toggles?
Regards,
MarinaApril 13, 2023 at 11:30 pm #1404417Hi,
You will need to add a custom class to the links to your accordion toggles or we could have it work only on certain pages.Best regards,
MikeApril 13, 2023 at 11:53 pm #1404419Hi Mike,
I would prefer to use a custom class. Something like the following will do?
<a href="#wps-hide-login" class="link-to-accordion">WPS Hide Login</a>
Regards,
MarinaApril 14, 2023 at 12:30 am #1404424Hi,
If you are using the custom class link-to-accordion then this should work:function anchor_offset_with_slow_scroll() { ?> <script> (function($) { $('a.link-to-accordion[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top - 100 //offsets for fixed header }, 1000); return false; } } }); }(jQuery)); </script> <?php } add_action('wp_footer', 'anchor_offset_with_slow_scroll');
If not then please add the class to the test link Comparing WPML
Best regards,
MikeApril 17, 2023 at 5:09 pm #1404711Hi Mike,
Thank you for your help, now everything works perfectly.
Could you please have a look at one issue as well? The two buttons on the page in private content display images in a lightbox, however, sometimes the title there is “null”. It is quite difficult to reproduce the issue. Is it possible to impose manually a title for each lightbox? There are four such lightboxes: two in English version and two in the Russian one.
Thank you,
MarinaApril 17, 2023 at 6:47 pm #1404733Hi,
Thanks for the feedback, I checked the button “sitemap example” and while the title in the lightbox showed in my tests, I do see that you are using a script to remove the title on hover, probably for images or another element and it needs to be adjusted to exclude these buttons.
Please include an admin login and explain what titles need to be removed with the script.
Please also explain how to see the null error for the button lightbox, is in a certain browser or clicking back and forth between the buttons?Best regards,
MikeApril 17, 2023 at 8:50 pm #1404756Hi Mike,
To reproduce the error, open the site in the private mode, navigate to the Workflow page and click any of two buttons: if you do not get the “null”, open in a private mode again, after a couple of attempts (I normally need 3 or 4) it should reproduce.
I actually want that there are no titles on hover on these buttons, but it seems to sometimes remove the linked lightbox title as well. So the script should remove the title on hover for: images, text links, and buttons (normal and fullwidth).
Best regards,
Marina- This reply was modified 1 year, 7 months ago by Marina.
April 18, 2023 at 5:46 pm #1404825Hi,
Thanks for the login, I’m not seeing a link in the button, how is the link to the image added?
The image needs to have a title for it to show in the lightbox, the script adds the title back on click so it will show in the lightbox, but it seems that once in a while the lightbox is faster than the script. I have a hard time reproducing, like you said, we need to try 3 or 4 times, it’s hard to correct an issue that doesn’t occur all of the time.Best regards,
MikeApril 19, 2023 at 3:01 pm #1404950Hi Mike,
Trying to fix the issue, I edited the button code in the debug mode, now everything is back as it should be. The problem is that the lightbox takes the Button Title Attribute, and does not display the image title at all. Please have a look at the third button I added, it has an empty Button Title Attribute, but the image has a title. Maybe this can help?
Best regards,
MarinaApril 19, 2023 at 6:34 pm #1404975Hi,
Glad to hear that you have this sorted out, I was mistaken about which title was used, unless there is anything else we can assist with on this issue, shall we close this then?Best regards,
MikeApril 20, 2023 at 11:07 am #1405028Hi Mike,
Sorry, you did not understand me correctly, the issue is still there. I meant that the links are added to the buttons again normally. With respect to the issue: is it possible to make the respective lightboxes take the title from the image and not from the button? If not, thank you again for your help, and you can close the ticket.
Best regards,
MarinaApril 20, 2023 at 4:48 pm #1405061Hi,
Unfortunately not in this case because the image title is not used in the button element, only a link to the image.Best regards,
MikeApril 21, 2023 at 11:18 pm #1405209Hi Mike,
Thank you for your help anyway, you can close the ticket.
Best regards,
Marina -
AuthorPosts
- The topic ‘Link to an accordion’s tab scrolls too much down and hides the tab’s title’ is closed to new replies.