我想知道如何在按钮或选项卡上创建幻灯片效果,如网站stripe.com
这是我的设计
前端代码
<nav id="sw-nav-developers" class="nav flex-md-column justify-content-between justify-content-md-start nav-pills nav-pills-light nav-fill"><a class="nav-item nav-link text-md-left active" data-toggle="tab" href="#payasyou-tab"><i class="icon fas fa-code"></i> HTML Structure</a>
<hr class="mt-2">
<a class="nav-link accent" style="color:#db78dd;font-weight: 600;text-transform: uppercase;">Software Coverage <i class="icon fas fa-long-arrow-alt-right"></i></a>
<a class="nav-item nav-link text-md-left " data-toggle="tab" href="#basic-tab"><i class="icon fas fa-code"></i>Basic</a>
<a class="nav-item nav-link text-md-left" data-toggle="tab" href="#pro-tab"><i class="icon fab fa-sass"></i> Pro</a>
<a class="nav-item nav-link text-md-left" href="#premium-tab" data-toggle="tab"><i class="icon fas fa-retweet fa-rotate-90"></i> Premium</a> <a class="nav-item nav-link text-md-left" href="#exclusive-tab" data-toggle="tab"><i class="icon fas fa-exclamation-triangle"></i> Exclusive</a>
<hr class="mt-2"><a class="nav-link accent" style="color:#45b2e8;font-weight: 600;text-transform: uppercase;">Hardware Coverage <i class="icon fas fa-long-arrow-alt-right"></i></a>
<a class="nav-item nav-link text-md-left " data-toggle="tab" href="#oneyear-tab"><i class="icon fas fa-code"></i> HTML Structure</a> <a class="nav-item nav-link text-md-left" data-toggle="tab" href="#twoyear-tab"><i class="icon fab fa-sass"></i> SASS compiler</a> </nav>
现在我在悬停上实现了滑动效果,但是如何在单击按钮或激活按钮时实现此效果。
我使用的CSS
nav#sw-nav-developers a.nav-item {
position: relative;
width: 100%;
padding-left: 12px;
font-family: Camphor,Open Sans,Segoe UI,sans-serif;
text-align: left;
cursor: pointer;
border: none;
outline: none;
background: none;
-webkit-transition: color .3s;
transition: color .3s;
height: 34px;
transition:.5s;
}
.nav-pills-light .nav-link.active:before {
content:'';
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:rgba(50,50,93,.11);
overflow:hidden;
z-index:-99;
transform:scaleY(0);
transform-origin:bottom;
transition:transform 5s ease-in-out;
}
.nav-pills-light .nav-link.active:active:before {
transform:scaleY(1);
transform-origin:top;
}
请帮助我实现这一目标,以供参考,您可以在stripe.com上看到相同的效果
答案 0 :(得分:0)
难以理解您的要求,但是如果您说:hover设法实现了这一目标,以及单击或激活也可以实现这一目标,则需要两件事:
.nav-link.active:before ,
.nav-link:active:before ,
.nav-link:hover:before ,
.nav-link:focus:before {
/*your same code here */
};
此外,此规则也不正确:它是指 .nav-link 的类为 .active ,并且用户也在单击(按住)上的元素-这就是:active 的意思。
.nav-link.active:active:在{...}之前