简体   繁体   English

如何在按钮上单击时创建幻灯片效果

[英]How to create slide effect on button when clicked on one from another

I want to know how to create slide effect like website stripe.com on buttons or tabs 我想知道如何在按钮或标签上创建像网站stripe.com这样的幻灯片效果

stripe.com中的标签设计

Here is My design 这是我的设计

在此输入图像描述

Front end Code 前端代码

 <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>

now i achieve sliding effect on hover but how to achieve this on button click or active. 现在我实现了悬停的滑动效果,但如何在按钮单击或激活时实现此功能。

CSS which i used 我用过的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;
    }

please help me out to achieve this for reference you can see same effect on stripe.com 请帮助我实现此参考,您可以在stripe.com上看到相同的效果

Having trouble understanding what you are asking, but if you say you managed to achieve this with :hover, and what to achieve this also with click or active, you need two things: 无法理解你的要求,但如果你说你设法通过以下方式实现这一点:悬停,以及通过点击或活动实现这一点,你需要做两件事:

  1. also add an :active and/or :focus rule. 还添加:active和/或:focus规则。 Example : 示例:
    .nav-link.active:before ,
    .nav-link:active:before ,
    .nav-link:hover:before  ,
    .nav-link:focus:before  {
        /*your same code here */ 
    };
  1. Add code to add the .active class to the current element, and remove it from the siblings (which i'm guessing you have already managed to do). 添加代码以将.active类添加到当前元素,并将其从兄弟姐妹中删除(我猜你已经设法做到了)。

Also, this rule is not right : it refers to when the .nav-link has a class of .active and also the user is clicking (holding click down) on the element - that's what :active means. 此外,此规则不正确:它指的是.nav-link类具有.active且用户在元素上单击(按住单击) - 这就是:active表示。

.nav-link.active:active:before { ... } .nav-link.active:active:在{...}之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM