我非常困难创造这种类型的按钮效果.我想在点击时将主按钮“拆分”为两个新按钮.我把我最好的尝试放在
http://codepen.io/bananahavana/pen/LbpRqp这里(不要笑!)
$('.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>
我真的很感激一些见解:
>这种类型的按钮动画是什么,如果它有一个名字.
>关于如何完成它的建议.
谢谢!!
最佳答案 您可以使用CSS3转换实现该效果:转换和转换.
我希望这就是你的意愿.如果您有任何其他问题,请询问.
Here是这段代码的小提琴.
$(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>