//-https://dribbble.com/shots/1768850-Slide-animation
.emoji
.container
ul
li.is_active(color='#bc2828' emoji=' š') Apple
li(color='#d68a8a' emoji='š') Peach
li(color='#dd7e28' emoji='š') Orange
li(color='#e0c44f' emoji='š') Banana
li(color='#92bf7b' emoji='š') Pear
View Compiled
.centerme(){
top: 45%;
left: 50%;
transform: translate(-50%,-50%);
}
body{
background-color: #ececec;
transition: background-color .3s ease;
}
.emoji{
position: absolute;
margin-left: 20px;
.centerme();
font-size: 250px;
opacity: .2;
}
.container{
position: absolute;
.centerme();
}
ul{
list-style-type:none;
.is_active{
padding: 10px 15px;
cursor: default;
&:hover{
opacity:1;
}
}
li{
color: #222;
position: relative;
display: inline-block;
background-color: #fff;
border-radius: 100px;
vertical-align: middle;
min-width: 12px;
min-height: 12px;
padding: 0px;
transition: all .3s ease;
margin-right: 5px;
box-shadow: 0 1px 2px 0px rgba(0,0,0,.2);
cursor: hand;
cursor: pointer;
&:hover{
opacity:0.6;
}
}
}
View Compiled
var tabNames = [];
//loop thru all li element and grab all data, push them into an array of objects
$('li').each(function(index){
var _this = $(this);
var elem = {};
elem.name = _this.text();
elem.color = _this.attr('color');
elem.emoji = _this.attr('emoji');
tabNames.push(elem);
console.log(tabNames);
//if this li is active, take those data and apply to body
if (_this.hasClass('is_active')){
$('body').css('background-color',elem.color);
$('.emoji').text(elem.emoji);
} else {_this.text('')};
});
//on click change text value, bg data, emoji
$('li').on('click', function(e) {
var _this = $(this);
var _idx = _this.index();
_this.addClass('is_active');
_this.text(tabNames[_idx].name);
$('body').css('background-color',tabNames[_idx].color)
$('.emoji').text(tabNames[_idx].emoji);
_this.siblings().text('');
_this.siblings().removeClass('is_active');
});
This Pen doesn't use any external CSS resources.