- This topic has 17 replies, 2 voices, and was last updated 2 years, 11 months ago by
David.
-
AuthorPosts
-
March 27, 2023 at 9:00 am #2584375
eastwood501
Hi, this is a question for David.
I have created a hook/element for a sticky left hand side Orange button.
I am using Davids tutorial on the javascript for making the sticky button appear after scroll. (https://generatepress.com/forums/topic/make-element-appear-after-scroll/)
However, i am unable to get this to work, David are you able to assist on some CSS to make the orange button appear after scroll?
Thanks in advance.
March 27, 2023 at 12:49 pm #2584700David
StaffCustomer SupportHi there,
1. Edit the Button and in Advanced give it a HTML Anchor of:
sticky-button2. in the JS look for this line:
const watchedEL = document.querySelector('#see-buying-options');and change it to:
const watchedEL = document.querySelector('#sticky-button');Let me know once that is done
March 27, 2023 at 1:05 pm #2584714eastwood501
Hi David,
Thanks for your reply.
I have dont both steps 1 & 2 now.
Cheers
March 27, 2023 at 2:37 pm #2584790David
StaffCustomer SupportThe
sticky-buttonhas to be added to the Advanced > HTML Anchor field not in the CSS fieldMarch 27, 2023 at 2:55 pm #2584800eastwood501
Hi David,
My apologise, i have now added sticky-button under the HTML ANCHOR field and removed it from the CSS field.
Kind Regards
March 27, 2023 at 9:19 pm #2584956eastwood501
I have added some more information below, so far I have tried the CSS from the tutorial here https://generatepress.com/forums/topic/make-element-appear-after-scroll/ to the new script but its not working still.
Many thanks in advance.March 28, 2023 at 4:36 am #2585385David
StaffCustomer SupportUnfortunately you can’t just mix and match codes 🙂
Can you remove any Javascript and CSS related to making this button sticky. And then let me know.March 28, 2023 at 4:47 am #2585395eastwood501
Hi David,
I have removed any CSS and javascript that was related to the button. As per the homepage, the button is now fixed and in the top middle of the page.
RegardsMarch 28, 2023 at 5:49 am #2585488David
StaffCustomer SupportCan you clear any caches as i still see the scripts and CSS on that page.
March 28, 2023 at 6:03 am #2585505eastwood501
Hi David,
I have now purged and cleared the host and WordPress and cloudfare caches.
Hopefully clear on your end.March 28, 2023 at 8:21 am #2585797David
StaffCustomer SupportOK. Lets get the JS working first.
1. Create your Hook element, and set the Hook to
wp_footer2. Add this Code to the Hook:
<script> // debounce scroll eventListener function debounceX(func, wait = 10, immediate = true) { let timeout; return function() { let context = this, args = arguments; let later = function() { timeout = null; if (!immediate) func.apply(context, args); }; let callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }; // check position function checkScrollPosition() { let windowY = window.scrollY; let targetY = 600; // target scroll position if (windowY < targetY) { watchedEL.classList.remove('is-visible'); } else { watchedEL.classList.add('is-visible'); } scrollPos = windowY; } // add listener const watchedEL = document.querySelector('#sticky-button'); window.addEventListener('scroll', debounceX(checkScrollPosition)); </script>3. Set the Display Rules to the Entire site or wherever you want it displayed.
4. Publish that,
Then let me know
March 28, 2023 at 8:24 am #2585799eastwood501
Hi David,
Script has been place into wp footer element, rule set to entire site and now published!
Cheers
March 28, 2023 at 8:45 am #2585834David
StaffCustomer SupportCan you move the #sticky-button ID to the Container Block that the buttons site inside of. It currently has a
hide-on-mobileclass attached to it for reference.Can you purge those caches 🙂 Or maybe disable them whilst you’re developing
March 28, 2023 at 9:44 am #2585938eastwood501
Hi David,
I have removed the ‘hide on mobile’ and moved the #stick-button ID to the container block.
Cache purged as well.March 28, 2023 at 10:17 am #2585981David
StaffCustomer SupportNow add this CSS:
#sticky-button { position: fixed; left: 0; transform: rotate(90deg); transform-origin: bottom left; } #sticky-button .gb-button { opacity: 0; transform: translatey(100%); transition: all 0.4s ease-in-out; } #sticky-button.is-visible .gb-button { transform: translatey(0); opacity: 1; } -
AuthorPosts
- You must be logged in to reply to this topic.