I am super stuck creating this type of button effect. I want to make my main button "split" into two new buttons on click. I put together my best attempt on codepen here http://codepen.io/bananahavana/pen/LbpRqp (don't laugh!)
$('.button1').click(function() {
$('.button1').addClass('clicked');
$('.reveal').addClass('opened');
});
.container {
text-align: center;
background: blue;
position: relative;
width: 400px;
height: 50px;
}
a {
position: absolute;
left: 0;
right: 0;
margin: auto;
display: inline-block;
width: 80px;
color: white;
overflow: hidden;
text-decoration: none;
background: #cc0066;
padding: 1rem 2em;
border-radius: 5px;
}
.clicked {
width: 0;
padding: 1rem 0rem;
transition: all 0.5s ease-in-out;
display: flex;
justify-content: space-between;
}
.button2,
.button3 {
width: 0;
padding: 1rem 0rem;
}
.opened {
width: 80px;
padding: 1rem 2em;
height: 18px;
transition: all 0.5s ease-in-out 0.5s;
}
.button2 {
right: 0;
margin-left: 0;
}
.button3 {
left: 0;
margin-right: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<a class="button1" href="#">Button1</a>
<a class="reveal button2" href="#">Button 2</a>
<a class="reveal button3" href="#">Button 3</a>
</div>
I'd really appreciate some insight on:
Thanks!!
You can accomplish that effect with the CSS3 tranform:translate
and transition
.
I hope that is what you wish. If you have any further questions, please ask.
Here is a fiddle to this code.
$(function(){
$('#button1').on('click',function(){
$('#button2').addClass('animateToRight');
$('#button3').addClass('animateToLeft');
$('#button1').addClass('hide');
});
});
.hide{
opacity:0;
}
#button3, #button2{
-webkit-transition: -webkit-transform 2s; /* Safari */
transition: transform 2s;
}
#button1{
z-index:10;
-webkit-transition: opacity 2s; /* Safari */
transition: opacity 2s;
}
.animateToRight{
-webkit-transform: translate(100px); /* Safari */
transform: translate(100px);
}
.animateToLeft{
-webkit-transform: translate(-100px); /* Safari */
transform: translate(-100px);
}
button{
background-color: green;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
font-size: 16px;
position: absolute;
left: 50%;
top: 50%;
margin-top: -50px;
margin-left: -50px;
}
.blobs {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
background: white;
width: 400px;
height: 200px;
margin: auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="blobs">
<button id="button2">YYY</button>
<button id="button1">XXX</button>
<button id="button3">ZZZ</button>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With