Skip to content

Instantly share code, notes, and snippets.

@neicore
Created November 1, 2021 05:58
Show Gist options
  • Save neicore/fdb3b0bf080cd1d08bba409615185618 to your computer and use it in GitHub Desktop.
Save neicore/fdb3b0bf080cd1d08bba409615185618 to your computer and use it in GitHub Desktop.
function getElement(element) {
return document.querySelector(element)
}
function createAnElement(elementName, className) {
let newElement = document.createElement(elementName)
newElement.setAttribute("class", className)
return newElement
}
// Bot Container
let sarufiBot = createAnElement("div", ".sarufi-bot")
sarufiBot.style.position = "fixed"
sarufiBot.style.bottom = "30px"
sarufiBot.style.right = "30px"
document.body.appendChild(sarufiBot)
// Chat Box Activation Button
let botButton = createAnElement("button", "bot-button")
botButton.textContent = "Chati Nasi"
botButton.style.cssText = `
background-image: linear-gradient(to right, #77A1D3 0%, #79CBCA 51%, #77A1D3 100%);
background-size: 200% auto;
border: none;
outline: none;
padding: 10px 20px;
border-radius: 50px;
box-shadow: 0 0 20px rgba(0, 0, 0 ,0.3);
transition: 0.5s;
color: #fff;
font-size: 14px;
letter-spacing: 0.5px;
cursor: pointer;
`
botButton.onmouseover = function () {
this.style.backgroundPosition = "right center"
this.style.transform = "scale(1.1)"
}
botButton.onmouseleave = function () {
this.style.backgroundPosition = "left center"
this.style.transform = "scale(1)"
}
sarufiBot.appendChild(botButton)
// Chat Box
let chatBox = createAnElement("div", ".chat-box")
sarufiBot.appendChild(chatBox)
chatBox.style.cssText = `
position: fixed;
bottom: 90px;
right: 30px;
width: 400px;
height: 600px;
background: #fff;
box-shadow: 0 0 50px rgba(0, 0, 0 ,0.1);
transition: height 0.2s ease-in;
`
// Show/Hide the chat box
botButton.addEventListener("click", function () {
if (chatBox.style.height !== "0px") {
chatBox.style.height = "0px"
botButton.textContent = "Chati Nasi"
} else {
chatBox.style.height = "600px"
botButton.textContent = "X"
}
})
// Chatbox Header
let chatBoxHeader = createAnElement("div", ".chat-box-header")
chatBox.appendChild(chatBoxHeader)
// Chatbox Body
let chatBoxBody = createAnElement("div", ".chat-box-body")
chatBox.appendChild(chatBoxBody)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment