Skip to content

Instantly share code, notes, and snippets.

@Nemra1
Created March 17, 2020 00:42
Show Gist options
  • Save Nemra1/abf9d6cf213f02f960c34f2bb9af54e4 to your computer and use it in GitHub Desktop.
Save Nemra1/abf9d6cf213f02f960c34f2bb9af54e4 to your computer and use it in GitHub Desktop.
Live Chat Options Popup
<ul class="webchat">
<li><a href="#">Email</a></li>
<li><a href="#">Live Chat</a></li>
<li><a href="#">Call Back</a></li>
<li><a class="show" href="#">Chat Options</a></li>
</ul>
jQuery(".show").click(function(e){
e.preventDefault();
let items = jQuery(this).parent().siblings();
if (jQuery(this).parent().parent().hasClass("open")) {
jQuery("ul.webchat").removeClass("open");
for (let i = 0; i < items.length; i++) {
jQuery(items[i]).css("transform", "translateY(0%)");
}
}
else {
jQuery("ul.webchat").addClass("open");
for (let i = 0; i < items.length; i++) {
let multiplier = items.length - i;
let percentOffset = -100 * multiplier + '%';
let marginOffset = 15 * multiplier + 'px';
//console.log("translateY(calc(" + percentOffset + " - " + marginOffset + "))");
jQuery(items[i]).css("transform", "translateY(calc(" + percentOffset + " - " + marginOffset + "))");
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
ul.webchat {
display: table;
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
font-family: sans-serif;
}
ul.webchat > li:not(:last-child) {
position: absolute;
z-index: -1;
opacity: 0;
transition: all 600ms cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
ul.webchat.open > li:not(:last-child) {
position: absolute;
opacity: 1;
z-index: -1;
}
ul.webchat li a {
display: block;
height: 48px;
line-height: 48px;
text-decoration: none;
}
ul.webchat li a:before {
content: "";
display: block;
float: left;
width: 48px;
height: 48px;
border-radius: 50%;
margin-right: 15px;
background: crimson;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment