- This topic has 12 replies, 3 voices, and was last updated 3 years, 5 months ago by
Tan.
-
AuthorPosts
-
October 18, 2022 at 9:38 am #2377834
Tan
Hi there,
I have a Call button element on my site (mobile version). It always shows at the bottom when the website has finished loading.
If I want the Call button element to show only when a visitor scrolls down to the footer like the effect of back to top button, is there any option or CSS code snippet for that?
Thank you.
October 18, 2022 at 10:38 am #2377882Ying
StaffCustomer SupportHi Tan,
It will require custom JS, CSS only can not work in that way.
You should be able to find a lot examples to learn from, eg.
https://webdesign.tutsplus.com/tutorials/animate-on-scroll-with-javascript–cms-36671October 18, 2022 at 5:57 pm #2378181Tan
Hi Ying,
I follow this guide from David. It works perfectly when people scroll to the footer.
Could you help me adjust this snippet from David to make the button show up once I hit 300px from the top of the page?
Thank you.
October 20, 2022 at 4:06 am #2379813David
StaffCustomer SupportHi there,
for scroll position from top then use the JS method provided here:
October 20, 2022 at 7:22 am #2380006Tan
Hi David,
Could you explain in more detail how to use this snippet in my scenario?
I’m not too familiar with coding. So can you teach me step by step like you did there? 😀
I’m so grateful for that.
October 20, 2022 at 8:34 am #2380198David
StaffCustomer SupportOk, so i the original code, you have the Javascript and the CSS.
Leave the CSS as is.
Change the Javacript to:<script> var scrollpos = window.scrollY; var header = document.querySelectorAll('.site-footer'); function add_class_on_scroll() { header[0].classList.add("in-view"); } function remove_class_on_scroll() { header[0].classList.remove("in-view"); } window.addEventListener('scroll', function(){ scrollpos = window.scrollY; if(scrollpos > 10){ add_class_on_scroll(); } else { remove_class_on_scroll(); } }); </script>October 20, 2022 at 5:01 pm #2380569Tan
I have a fatal error on line 1 when applying the JavaScript. It is like this.
Can you check it again?October 20, 2022 at 5:32 pm #2380583Tan
Sorry David. It’s my fault for PHP error.
Now I fix it following your guide, but the call button doesn’t appear anymore 🙁
October 21, 2022 at 2:57 am #2380921David
StaffCustomer SupportWhere can i see this ?
October 21, 2022 at 3:01 am #2380930Tan
You can see it in private information box (include temporary login link)
October 24, 2022 at 8:01 pm #2384786Tan
Hi David,
Can you help me take a look?
Thank you
October 25, 2022 at 2:45 am #2385162David
StaffCustomer SupportI made a mistake in the JS. I just updated the script in your Call Button Animation Hook. And updated the code above.
This line of the code:
if(scrollpos > 10){The 10 is the number of pixels from the top of the page, increase that to 300
November 3, 2022 at 8:13 pm #2400828Tan
Thank you so much David. It worked like a charm! 😀
-
AuthorPosts
- You must be logged in to reply to this topic.