首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >制作背景幻灯片动画

制作背景幻灯片动画
EN

Stack Overflow用户
提问于 2017-12-06 21:06:20
回答 0查看 489关注 0票数 5

我做了一个按钮组,希望当用户选择上一个或下一个按钮的背景移动/滑动到选定的按钮时,我用纯css做了这个效果,只是用jquery来添加或删除active类。现在的问题是,当你点击All按钮,然后它工作正常,但如果你点击Used幻灯片不工作在正确的位置。

为了达到这个效果,我使用了transition::before,需要用纯css或最少的jquery来解决这个问题,而不是用很多javascriptjquery代码。

移动此背景的逻辑是:

代码语言:javascript
运行
复制
.RadioButton .btn:first-child::before {
 right: 0;
 transition: .3s all ease;
}

.RadioButton .btn:nth-child(2)::before {
 transition: .3s all ease;
}

.RadioButton .btn:last-child::before {
  left: 0;
  transition: .3s all ease;
}

.RadioButton .btn:nth-child(2)::before上的问题我不能使用right:0left:0,因为如果我使用每一个,滑动效果不能在正确的位置工作,有什么解决方案吗?

到目前为止,我尝试了以下内容:

代码语言:javascript
运行
复制
$('.RadioButton').each(function(){
	$(this).find('.btn').each(function(){
		$(this).click(function(){
			$(this).parent().find('.btn').removeClass('btn-active');
			$(this).addClass('btn-active');
		});
	});
});
代码语言:javascript
运行
复制
body {
direction: rtl;
}

.RadioButton .btn {
    width: 33%;
    float: left;
    margin: 0;
    box-sizing: border-box;
    position: relative;
    font-size: 11px;
    min-height: 30px!important;
    line-height: 30px;
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer;
    text-align: center;
}

.btn-default {
    border: 1px solid gray;
    color: gray;
}

.btn-group>.btn:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.btn-group>.btn:nth-child(2) {
    border-radius: 0;
}

.btn-group>.btn:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.RadioButton .btn::before {
    content: "";
    height: 100%;
    width: 0%;
    background: gray;
    position: absolute;
    top: 0;
    transition: .3s all ease;
    z-index: -1;
}

.btn-active::before {
    width: 100%!important;
}

.RadioButton .btn:nth-child(2)::before {
 right: 0;
 transition: .3s all ease;
}

.RadioButton .btn:last-child::before {
  left: 0;
  transition: .3s all ease;
}

.btn-active:first-child::before {
 left: 0;
 transition: .3s all ease;
}

.btn-active:last-child::before {
  left: 0;
  transition: .3s all ease;
}

.btn.btn-default.btn-active {
    color: white;
}

.btn-group {
    clear: both;
    margin-top: 10px;
}
代码语言:javascript
运行
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="RadioButton btn-group" id="searchType">
	<a class="btn btn-default" data-val="0">Used</a>
	<a class="btn btn-default" data-val="1">New</a>
	<a class="btn btn-default btn-active" data-val="2">All</a>
</div>

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47675041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档