Pop Up Widget that calls Users Attention on scroll...
# 📖tutorials
n
Hi all, that my first tutorial and easy. Sometimes happens that a visitor on your website doesn´t realize that there is the possibility to chat with your bot. To call the attention of the user or to offer more Help trough the Chat option is a nice way to have more features for the User and is more attractive too. Here is what I have done: Hopefully not to complicated 😅 Result is this, as show case example:
Here the code complete: It gooes just right after footer: .popup { position: fixed; bottom: 40px; /* Adjust the distance from the bottom as needed */ right: 60px; /* Adjust the distance from the right as needed */ padding: 20px; border-radius: 10px; box-shadow: none; z-index: 9999; cursor: pointer; display: flex; justify-content: right; overflow: hidden; /* Ensure the image fits within the pop-up */ } .popup img { width: 20%; /* Adjust the image size to fit the pop-up */ height: 20%; border-radius: 10px; }
window.addEventListener("DOMContentLoaded", function() { var popupDisplayed = false; function showPopup() { if (!popupDisplayed) { // Create the pop-up element var popup = document.createElement("div"); popup.className = "popup"; // Create the pop-up image var popupImage = document.createElement("img"); popupImage.src = "img/popup.png"; /* Replace 'path/to/designed-image.png' with the actual path to your designed image */ popup.appendChild(popupImage); // Append the pop-up to the body document.body.appendChild(popup); popupDisplayed = true; } } function showChatWidget() { var chatWidget = document.getElementById("botpress-webchat"); chatWidget.style.display = "block"; document.body.removeChild(document.getElementById("popup")); } // Show the pop-up when scrolling down a few lines window.addEventListener("scroll", function() { if (window.scrollY > 100) { // Adjust the scroll position as needed showPopup(); } }); // Show the chat widget when the pop-up is clicked document.addEventListener("click", function(event) { var popup = document.getElementById("popup"); if (event.target === popup) { showChatWidget(); } }); });
:: :: This code might be complicated but that what I have achieved and it works.
s
@narrow-agent-91470 So i just copy and paste it?
n
Right, make sure you change the parts needed
s
How should I place the image
n
in the img folder of your website
s
i dont got that
its only a test site
n
you can make the image as big or small you like to, just adjust the CSS
s
its only a test site
n
but you access the HTML code, isn´t it
s
yeah
n
you have access to the different folders to, where you store the CSS and images?
s
its only index.html file lol
i want to do that for a client
n
I got you, but does your website has images?
s
no
n
ok then make a folder that you call img
just in the same directory as your index.html is stored
s
so dekstop ok
n
there you have your index.html
?
s
thats right
n
Best is if you create a folder that says something like Website, then store your index.html inside and create there the folder for images called img
then create an image or download one that you like to pop up
that you store in the img folder
give it a name like - pop up.png (if it is a png) what I suiggest because then you can remove the background
s
done
n
have you an image already?
s
yeah
n
what´s the name and format?
s
png format
123 name
n
ok
wait a sec
this code you can just copy and paste below the footer section: .popup { position: fixed; bottom: 40px; /* Adjust the distance from the bottom as needed / right: 60px; / Adjust the distance from the right as needed / padding: 20px; border-radius: 10px; box-shadow: none; z-index: 9999; cursor: pointer; display: flex; justify-content: right; overflow: hidden; / Ensure the image fits within the pop-up / } .popup img { width: 20%; / Adjust the image size to fit the pop-up */ height: 20%; border-radius: 10px; }
that is a stylesheet
you could make a folder for that too
but never mind for now
s
so know how do I add the image
n
on your botpress site you have two codes, for your bot
s
yes
n
that one you put first
fromm your site
s
then
j
ima try and make one with CHATgpt 🙂
wish me luck !
n
then you put this code: window.addEventListener("DOMContentLoaded", function() { var popupDisplayed = false; function showPopup() { if (!popupDisplayed) { // Create the pop-up element var popup = document.createElement("div"); popup.className = "popup"; // Create the pop-up image var popupImage = document.createElement("img"); popupImage.src = "img/123.png"; /* Replace 'path/to/designed-image.png' with the actual path to your designed image */ popup.appendChild(popupImage); // Append the pop-up to the body document.body.appendChild(popup); popupDisplayed = true; } } function showChatWidget() { var chatWidget = document.getElementById("botpress-webchat"); chatWidget.style.display = "block"; document.body.removeChild(document.getElementById("popup")); } // Show the pop-up when scrolling down a few lines window.addEventListener("scroll", function() { if (window.scrollY > 100) { // Adjust the scroll position as needed showPopup(); } }); // Show the chat widget when the pop-up is clicked document.addEventListener("click", function(event) { var popup = document.getElementById("popup"); if (event.target === popup) { showChatWidget(); } }); });
j
oh thanks !
n
I have already added the image
j
nevermind
n
that would be the part of adding the img: popupImage.src = "img/123.png"; /* Replace 'path/to/designed-image.png' with the actual path to your designed image */
s
how can ichange the path
n
popupImage.src = "img/123.png"; popupImage.src decribes the variable = "img/123.png" is the image path img is the folder and 123.png is the image name
s
so i just copy it
n
yes
here for you
window.addEventListener("DOMContentLoaded", function() { var popupDisplayed = false; function showPopup() { if (!popupDisplayed) { // Create the pop-up element var popup = document.createElement("div"); popup.className = "popup"; // Create the pop-up image var popupImage = document.createElement("img"); popupImage.src = "img/123.png"; /* Replace 'path/to/designed-image.png' with the actual path to your designed image */ popup.appendChild(popupImage); // Append the pop-up to the body document.body.appendChild(popup); popupDisplayed = true; } } function showChatWidget() { var chatWidget = document.getElementById("botpress-webchat"); chatWidget.style.display = "block"; document.body.removeChild(document.getElementById("popup")); } // Show the pop-up when scrolling down a few lines window.addEventListener("scroll", function() { if (window.scrollY > 100) { // Adjust the scroll position as needed showPopup(); } }); // Show the chat widget when the pop-up is clicked document.addEventListener("click", function(event) { var popup = document.getElementById("popup"); if (event.target === popup) { showChatWidget(); } }); });
s
like this?
n
copy and paste that
s
ok
then
n
then you put the second botpress script from your botpress site
s
below everything right?
n
s
done
n
alright, then run your page and check it out
s
nothing happens 😄
n
can you make a screenshot
of your code
too
s
n
you have made a script file?
the code goes inside the index.html
below the footer
and just above the body closing
s
what should I fix
sry for being so annoying
n
open the index.html
never mind, I have issues in my network, so am free right now
s
ok
maybe the issue is that i cant scroll on my website
n
below the footer there you paste alll the code
/footer
s
where is that 😄
n
wait
here a testsite
complete
s
what should I do with it
n
wait
this is a complete basic website
use the code
if needed
there I have implimented your img
you need to change the two script provided from botpress
I have marked them sayinn Change HERE
@strong-iron-51380
This part of the script; // Show the pop-up when scrolling down a few lines window.addEventListener("scroll", function() { if (window.scrollY > 100) { // Adjust the scroll position as needed showPopup(); } });
you can change the line from where it pop up
instead of 100 like in my case you can put 200 or 50
that´s on you
s
ty mate
b
should I put this code in the css chatbot styler or html in my site ?
a
can u help me with that?
n
Hey RonRonXR I am sorry, but my health conditions are not the best at this moment. Am not able to be active at that point. Really sorry and hoppe you understand.
a
feel good nrother
4 Views