我试图将css过渡效果添加到元素中,如下所示:
$('.trans-opener').click(function () {
$(this).nextAll().slice(0, 3).toggleClass('trans-hidden');
});

.row{
padding: 50px;
}
.trans-hidden {
display: none;
position: absolute;
right: 15px;
}
ul{
list-style:none;
margin:0px;
padding:0px;
}
ul li {
float: right;
padding-left: 15px;
}
ul li .icon {
height: 32px;
width: 32px;
background-color: #cdcdcd;
line-height: 35px;
border-radius: 50%;
transition: all 0.3s;
}

<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-xs-3">
<div></div>
</div>
<div class="col-xs-9">
<ul>
<li class="trans-opener"><a href="#"><div class="icon"><i class="fa fa-ellipsis-h"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-facebook"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-twitter"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-heart"></i></div></a>
</li>
</ul>
</div>
</div>
&#13;
当我点击(...)三点图标时,会出现其他图标。但我试图给图标赋予过渡效果。我试过了transition: all 0.3s;
,但它没有用。任何帮助都会非常明显。
提前致谢。
答案 0 :(得分:1)
使用jQuery fadeIn()
函数可能会更容易实现,如下所示:
$('.trans-opener').click(function () {
$(this).nextAll().slice(0, 3).fadeToggle();
});
.row{
padding: 50px;
}
.trans-hidden {
display: none;
/*position: absolute;*/
right: 15px;
}
ul{
list-style:none;
margin:0px;
padding:0px;
}
ul li {
float: right;
padding-left: 15px;
}
ul li .icon {
height: 32px;
width: 32px;
background-color: #cdcdcd;
line-height: 35px;
border-radius: 50%;
transition: all 0.3s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-xs-3">
<div></div>
</div>
<div class="col-xs-9">
<ul>
<li class="trans-opener"><a href="#"><div class="icon"><i class="fa fa-ellipsis-h"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-facebook"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-twitter"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-heart"></i></div></a>
</li>
</ul>
</div>
</div>
如果您希望它们展开(即向右移动),您需要单独指定每个位置。试试这个:
$('.trans-opener').click(function () {
var icons = $(this).nextAll().slice(0, 3)
if(icons.is(":visible")){
$(icons).animate({right: 60}, function(){ icons.toggle(); });
}
else{
icons.toggle();
$(icons[0]).animate({right: 200});
$(icons[1]).animate({right: 150});
$(icons[2]).animate({right: 100});
}
});
.row{
padding: 50px;
}
.trans-hidden {
display: none;
position: absolute;
right: 60px;
}
ul{
list-style:none;
margin:0px;
padding:0px;
}
ul li {
float: right;
padding-left: 15px;
}
ul li .icon {
height: 32px;
width: 32px;
background-color: #cdcdcd;
line-height: 35px;
border-radius: 50%;
transition: all 0.3s;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="row">
<div class="col-xs-3">
<div></div>
</div>
<div class="col-xs-9">
<ul>
<li class="trans-opener"><a href="#"><div class="icon"><i class="fa fa-ellipsis-h"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-facebook"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-twitter"></i></div></a>
</li>
<li class="trans-hidden"><a href="#"><div class="icon"><i class="fa fa-heart"></i></div></a>
</li>
</ul>
</div>
</div>
答案 1 :(得分:0)
您可以使用关键帧,使图标可设置为动画,首先必须在动画的早期阶段设置display:block。对于fadeIn动画,您可以使用。
ul li .icon {
height: 32px;
width: 32px;
background-color: #cdcdcd;
line-height: 35px;
border-radius: 50%;
animation: fadeInCustom 1s;
}
@keyframes fadeInCustom {
0% {
display: none;
opacity: 0;
}
1% {
display: block;
opacity: 0;
}
100% {
display: block;
opacity: 1;
}
}