- This topic has 3 replies, 2 voices, and was last updated 2 years, 7 months ago by
David.
-
AuthorPosts
-
February 11, 2023 at 2:39 pm #2529870
Piotr
Hi,
I’m working on my personal website. I’d like to make a sticky menu button with difference blending mode (mix-blend-mode: difference), but I couldn’t achieve deisred effect with GeneratePress standard sticky menu option. Alternatively, I created a custom sticky button, which almost do the job. The problem is I don’t know how to make the button fade in after the user has scrolled for a bit (like in standard sticky menu option). Is there any solution to do the trick?I tried this code from David:
https://generatepress.com/forums/topic/bottom-sticky-works-now-want-to-load-on-scroll/…and this:
https://generatepress.com/forums/topic/make-element-appear-after-scroll/Unfortunately, both solutions didn’t work for me…
Many thanks,
PiotrFebruary 12, 2023 at 4:59 am #2530211David
StaffCustomer SupportHi there,
second option should work fine here.
1. edit your
<button>
HTML and give it an ID eg.sticky-menu
2. Add the script:
<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-menu'); window.addEventListener('scroll', debounceX(checkScrollPosition)); </script>
Note this line:
const watchedEL = document.querySelector('#sticky-menu');
is where we declare the buttons ID.
Edit this line:let targetY = 600;
to set how far in pixels a user has to scroll before theis-visible
class is toggleed on thebutton#sticky-menu
element.3, the CSS needs to change to match your elements ID:
#sticky-menu { opacity: 0; pointer-events: none; transition: all 0.3s ease-in; } #sticky-menu.is-visible { opacity: 1; pointer-events: auto; }
February 12, 2023 at 5:28 am #2530225Piotr
Hi David,
now it works like a charm. Your support is always the best. I don’t know how to thank you!
Sincerely,
PiotrFebruary 12, 2023 at 5:55 am #2530248David
StaffCustomer SupportYou’re welcome – glad to be of help!
-
AuthorPosts
- You must be logged in to reply to this topic.