为什么我不能在加载页面后更改活动类

时间:2017-12-20 04:44:56

标签: jquery html css

这是我的代码



$('.btn-toggle').click(function() {
  if ($('.btn-toggle').hasClass('active')) {
    $('.report-action-btn').css('opacity', '1');
  } else {
    $('report-action-btn').css('opacity', '0');
  }

  $(this).toggleClass('active');
});

/**** Toggle button ****/

.btn-toggle {
  margin: 0 4rem;
  padding: 0;
  position: relative;
  border: none;
  height: 1.5rem;
  width: 3rem;
  border-radius: 1.5rem;
  color: #6b7381;
  background: #bdc1c8;
}

.btn-toggle:focus,
.btn-toggle.focus,
.btn-toggle:focus.active,
.btn-toggle.focus.active {
  outline: none;
}

.btn-toggle:before,
.btn-toggle:after {
  line-height: 1.5rem;
  width: 4rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}


/*.btn-toggle:before {
  content: 'Off';
  left: -4rem;
}*/


/*.btn-toggle:after {
  content: 'On';
  right: -4rem;
  opacity: .5;
}*/

.btn-toggle>.handle {
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 1.125rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.active {
  transition: background-color 0.25s;
}

.btn-toggle.active>.handle {
  left: 1.6875rem;
  transition: left .25s;
}

.btn-toggle.active:before {
  opacity: .5;
}

.btn-toggle.active:after {
  opacity: 1;
}

.btn-toggle.btn-sm:before,
.btn-toggle.btn-sm:after {
  line-height: -0.5rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.4125rem;
  width: 2.325rem;
}

.btn-toggle.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-xs:before,
.btn-toggle.btn-xs:after {
  display: none;
}

.btn-toggle:before,
.btn-toggle:after {
  color: #6b7381;
}

.btn-toggle.active {
  background-color: #29b5a8;
}

.btn-toggle.btn-lg {
  margin: 0;
  padding: 0;
  position: relative;
  border: none;
  height: 2.5rem;
  width: 5rem;
  border-radius: 2.5rem;
}

.btn-toggle.btn-lg:focus,
.btn-toggle.btn-lg.focus,
.btn-toggle.btn-lg:focus.active,
.btn-toggle.btn-lg.focus.active {
  outline: none;
}

.btn-toggle.btn-lg:before,
.btn-toggle.btn-lg:after {
  line-height: 2.5rem;
  width: 5rem;
  text-align: center;
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}


/*.btn-toggle.btn-lg:before {
  content: 'Off';
  left: -5rem;
}
.btn-toggle.btn-lg:after {
  content: 'On';
  right: -5rem;
  opacity: .5;
}*/

.btn-toggle.btn-lg>.handle {
  position: absolute;
  top: 0.3125rem;
  left: 0.3125rem;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 1.875rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.btn-lg.active {
  transition: background-color 0.25s;
}

.btn-toggle.btn-lg.active>.handle {
  left: 2.8125rem;
  transition: left .25s;
}

.btn-toggle.btn-lg.active:before {
  opacity: .5;
}

.btn-toggle.btn-lg.active:after {
  opacity: 1;
}

.btn-toggle.btn-lg.btn-sm:before,
.btn-toggle.btn-lg.btn-sm:after {
  line-height: 0.5rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.6875rem;
  width: 3.875rem;
}

.btn-toggle.btn-lg.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-lg.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-lg.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-lg.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-lg.btn-xs:before,
.btn-toggle.btn-lg.btn-xs:after {
  display: none;
}

.btn-toggle.btn-sm {
  margin: 0 0.5rem;
  padding: 0;
  position: relative;
  border: none;
  height: 1.5rem;
  width: 3rem;
  border-radius: 1.5rem;
}

.btn-toggle.btn-sm:focus,
.btn-toggle.btn-sm.focus,
.btn-toggle.btn-sm:focus.active,
.btn-toggle.btn-sm.focus.active {
  outline: none;
}

.btn-toggle.btn-sm:before,
.btn-toggle.btn-sm:after {
  line-height: 1.5rem;
  width: 0.5rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}

.btn-toggle.btn-sm:before {
  content: 'Off';
  left: -0.5rem;
}

.btn-toggle.btn-sm:after {
  content: 'On';
  right: -0.5rem;
  opacity: .5;
}

.btn-toggle.btn-sm>.handle {
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 1.125rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.btn-sm.active {
  transition: background-color 0.25s;
}

.btn-toggle.btn-sm.active>.handle {
  left: 1.6875rem;
  transition: left .25s;
}

.btn-toggle.btn-sm.active:before {
  opacity: .5;
}

.btn-toggle.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-sm.btn-sm:before,
.btn-toggle.btn-sm.btn-sm:after {
  line-height: -0.5rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.4125rem;
  width: 2.325rem;
}

.btn-toggle.btn-sm.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-sm.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-sm.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-sm.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-sm.btn-xs:before,
.btn-toggle.btn-sm.btn-xs:after {
  display: none;
}

.btn-toggle.btn-xs {
  margin: 0 0;
  padding: 0;
  position: relative;
  border: none;
  height: 1rem;
  width: 2rem;
  border-radius: 1rem;
}

.btn-toggle.btn-xs:focus,
.btn-toggle.btn-xs.focus,
.btn-toggle.btn-xs:focus.active,
.btn-toggle.btn-xs.focus.active {
  outline: none;
}

.btn-toggle.btn-xs:before,
.btn-toggle.btn-xs:after {
  line-height: 1rem;
  width: 0;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}

.btn-toggle.btn-xs:before {
  content: 'Off';
  left: 0;
}

.btn-toggle.btn-xs:after {
  content: 'On';
  right: 0;
  opacity: .5;
}

.btn-toggle.btn-xs>.handle {
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 0.75rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.btn-xs.active {
  transition: background-color 0.25s;
}

.btn-toggle.btn-xs.active>.handle {
  left: 1.125rem;
  transition: left .25s;
}

.btn-toggle.btn-xs.active:before {
  opacity: .5;
}

.btn-toggle.btn-xs.active:after {
  opacity: 1;
}

.btn-toggle.btn-xs.btn-sm:before,
.btn-toggle.btn-xs.btn-sm:after {
  line-height: -1rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.275rem;
  width: 1.55rem;
}

.btn-toggle.btn-xs.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-xs.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-xs.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-xs.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-xs.btn-xs:before,
.btn-toggle.btn-xs.btn-xs:after {
  display: none;
}

.btn-toggle.btn-secondary {
  color: #6b7381;
  background: #bdc1c8;
}

.btn-toggle.btn-secondary:before,
.btn-toggle.btn-secondary:after {
  color: #6b7381;
}

.btn-toggle.btn-secondary.active {
  background-color: #ff8300;
}

.btn-toggle.btn-secondary.active {
  background-color: #ff8300;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<button type="button" class="report-sens-btn btn btn-lg btn-toggle" data-toggle="button" aria-pressed="true" autocomplete="off">
<div class="handle"></div>
</button>

<a class="report-action-btn btn btn-icon waves-effect waves-light btn-success m-b-5">
  <i class="fa fa-thumbs-o-up"></i>
</a>
&#13;
&#13;
&#13;

我希望切换按钮的时间为.active类,<a>标记为opacity:1,否则为opacity:0
这里的问题是当页面加载和按钮时单击以激活该按钮无法识别活动类

2 个答案:

答案 0 :(得分:1)

这适用于您:

只需添加以下代码即可点击页面加载。

$(window).load(function(){
  $('.btn-toggle').trigger('click');
});

并切换.report-action-btn的不透明度,您可以更好地使用CSS

.report-action-btn{
  opacity:0;
  background: red;/*remove this only for test*/
  display: inline-block;/*remove this only for test*/
  width: 10px;/*remove this only for test*/
  height: 10px;/*remove this only for test*/
}

.btn-toggle.active+.report-action-btn{
  opacity:1;
}

这里正在为您准备一份工作样本。

$('.btn-toggle').click(function() {
  $(this).toggleClass('active');
});

$(window).load(function() {
  $('.btn-toggle').trigger('click');
});
/**** Toggle button ****/

.btn-toggle {
  margin: 0 4rem;
  padding: 0;
  position: relative;
  border: none;
  height: 1.5rem;
  width: 3rem;
  border-radius: 1.5rem;
  color: #6b7381;
  background: #bdc1c8;
}

.btn-toggle:focus,
.btn-toggle.focus,
.btn-toggle:focus.active,
.btn-toggle.focus.active {
  outline: none;
}

.btn-toggle:before,
.btn-toggle:after {
  line-height: 1.5rem;
  width: 4rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}


/*.btn-toggle:before {
  content: 'Off';
  left: -4rem;
}*/


/*.btn-toggle:after {
  content: 'On';
  right: -4rem;
  opacity: .5;
}*/

.btn-toggle>.handle {
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 1.125rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.active {
  transition: background-color 0.25s;
}

.btn-toggle.active>.handle {
  left: 1.6875rem;
  transition: left .25s;
}

.btn-toggle.active:before {
  opacity: .5;
}

.btn-toggle.active:after {
  opacity: 1;
}

.btn-toggle.btn-sm:before,
.btn-toggle.btn-sm:after {
  line-height: -0.5rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.4125rem;
  width: 2.325rem;
}

.btn-toggle.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-xs:before,
.btn-toggle.btn-xs:after {
  display: none;
}

.btn-toggle:before,
.btn-toggle:after {
  color: #6b7381;
}

.btn-toggle.active {
  background-color: #29b5a8;
}

.btn-toggle.btn-lg {
  margin: 0;
  padding: 0;
  position: relative;
  border: none;
  height: 2.5rem;
  width: 5rem;
  border-radius: 2.5rem;
}

.btn-toggle.btn-lg:focus,
.btn-toggle.btn-lg.focus,
.btn-toggle.btn-lg:focus.active,
.btn-toggle.btn-lg.focus.active {
  outline: none;
}

.btn-toggle.btn-lg:before,
.btn-toggle.btn-lg:after {
  line-height: 2.5rem;
  width: 5rem;
  text-align: center;
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}


/*.btn-toggle.btn-lg:before {
  content: 'Off';
  left: -5rem;
}
.btn-toggle.btn-lg:after {
  content: 'On';
  right: -5rem;
  opacity: .5;
}*/

.btn-toggle.btn-lg>.handle {
  position: absolute;
  top: 0.3125rem;
  left: 0.3125rem;
  width: 1.875rem;
  height: 1.875rem;
  border-radius: 1.875rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.btn-lg.active {
  transition: background-color 0.25s;
}

.btn-toggle.btn-lg.active>.handle {
  left: 2.8125rem;
  transition: left .25s;
}

.btn-toggle.btn-lg.active:before {
  opacity: .5;
}

.btn-toggle.btn-lg.active:after {
  opacity: 1;
}

.btn-toggle.btn-lg.btn-sm:before,
.btn-toggle.btn-lg.btn-sm:after {
  line-height: 0.5rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.6875rem;
  width: 3.875rem;
}

.btn-toggle.btn-lg.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-lg.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-lg.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-lg.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-lg.btn-xs:before,
.btn-toggle.btn-lg.btn-xs:after {
  display: none;
}

.btn-toggle.btn-sm {
  margin: 0 0.5rem;
  padding: 0;
  position: relative;
  border: none;
  height: 1.5rem;
  width: 3rem;
  border-radius: 1.5rem;
}

.btn-toggle.btn-sm:focus,
.btn-toggle.btn-sm.focus,
.btn-toggle.btn-sm:focus.active,
.btn-toggle.btn-sm.focus.active {
  outline: none;
}

.btn-toggle.btn-sm:before,
.btn-toggle.btn-sm:after {
  line-height: 1.5rem;
  width: 0.5rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}

.btn-toggle.btn-sm:before {
  content: 'Off';
  left: -0.5rem;
}

.btn-toggle.btn-sm:after {
  content: 'On';
  right: -0.5rem;
  opacity: .5;
}

.btn-toggle.btn-sm>.handle {
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 1.125rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.btn-sm.active {
  transition: background-color 0.25s;
}

.btn-toggle.btn-sm.active>.handle {
  left: 1.6875rem;
  transition: left .25s;
}

.btn-toggle.btn-sm.active:before {
  opacity: .5;
}

.btn-toggle.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-sm.btn-sm:before,
.btn-toggle.btn-sm.btn-sm:after {
  line-height: -0.5rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.4125rem;
  width: 2.325rem;
}

.btn-toggle.btn-sm.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-sm.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-sm.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-sm.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-sm.btn-xs:before,
.btn-toggle.btn-sm.btn-xs:after {
  display: none;
}

.btn-toggle.btn-xs {
  margin: 0 0;
  padding: 0;
  position: relative;
  border: none;
  height: 1rem;
  width: 2rem;
  border-radius: 1rem;
}

.btn-toggle.btn-xs:focus,
.btn-toggle.btn-xs.focus,
.btn-toggle.btn-xs:focus.active,
.btn-toggle.btn-xs.focus.active {
  outline: none;
}

.btn-toggle.btn-xs:before,
.btn-toggle.btn-xs:after {
  line-height: 1rem;
  width: 0;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  position: absolute;
  bottom: 0;
  transition: opacity .25s;
}

.btn-toggle.btn-xs:before {
  content: 'Off';
  left: 0;
}

.btn-toggle.btn-xs:after {
  content: 'On';
  right: 0;
  opacity: .5;
}

.btn-toggle.btn-xs>.handle {
  position: absolute;
  top: 0.125rem;
  left: 0.125rem;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 0.75rem;
  background: #fff;
  transition: left .25s;
}

.btn-toggle.btn-xs.active {
  transition: background-color 0.25s;
}

.btn-toggle.btn-xs.active>.handle {
  left: 1.125rem;
  transition: left .25s;
}

.btn-toggle.btn-xs.active:before {
  opacity: .5;
}

.btn-toggle.btn-xs.active:after {
  opacity: 1;
}

.btn-toggle.btn-xs.btn-sm:before,
.btn-toggle.btn-xs.btn-sm:after {
  line-height: -1rem;
  color: #fff;
  letter-spacing: .75px;
  left: 0.275rem;
  width: 1.55rem;
}

.btn-toggle.btn-xs.btn-sm:before {
  text-align: right;
}

.btn-toggle.btn-xs.btn-sm:after {
  text-align: left;
  opacity: 0;
}

.btn-toggle.btn-xs.btn-sm.active:before {
  opacity: 0;
}

.btn-toggle.btn-xs.btn-sm.active:after {
  opacity: 1;
}

.btn-toggle.btn-xs.btn-xs:before,
.btn-toggle.btn-xs.btn-xs:after {
  display: none;
}

.btn-toggle.btn-secondary {
  color: #6b7381;
  background: #bdc1c8;
}

.btn-toggle.btn-secondary:before,
.btn-toggle.btn-secondary:after {
  color: #6b7381;
}

.btn-toggle.btn-secondary.active {
  background-color: #ff8300;
}

.btn-toggle.btn-secondary.active {
  background-color: #ff8300;
}

.report-action-btn{
  opacity:0;
  background: red;/*remove this only for test*/
  display: inline-block;/*remove this only for test*/
  width: 10px;/*remove this only for test*/
  height: 10px;/*remove this only for test*/
}

.btn-toggle.active+.report-action-btn{
  opacity:1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<button type="button" class="report-sens-btn btn btn-lg btn-toggle" data-toggle="button" aria-pressed="true" autocomplete="off">
<div class="handle"></div>
</button>

<a class="report-action-btn btn btn-icon waves-effect waves-light btn-success m-b-5">
  <i class="fa fa-thumbs-o-up"></i>
</a>

希望这对你有所帮助。

答案 1 :(得分:0)

  1. 手动调用click事件
  2. &#13;
    &#13;
    $('.btn-toggle').click(function() {
      if ($('.btn-toggle').hasClass('active')) {
        $('.report-action-btn').css('opacity', '1');
      } else {
        $('report-action-btn').css('opacity', '0');
      }
    
      $(this).toggleClass('active');
    }).click();
    &#13;
    /**** Toggle button ****/
    
    .btn-toggle {
      margin: 0 4rem;
      padding: 0;
      position: relative;
      border: none;
      height: 1.5rem;
      width: 3rem;
      border-radius: 1.5rem;
      color: #6b7381;
      background: #bdc1c8;
    }
    
    .btn-toggle:focus,
    .btn-toggle.focus,
    .btn-toggle:focus.active,
    .btn-toggle.focus.active {
      outline: none;
    }
    
    .btn-toggle:before,
    .btn-toggle:after {
      line-height: 1.5rem;
      width: 4rem;
      text-align: center;
      font-weight: 600;
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: 2px;
      position: absolute;
      bottom: 0;
      transition: opacity .25s;
    }
    
    
    /*.btn-toggle:before {
      content: 'Off';
      left: -4rem;
    }*/
    
    
    /*.btn-toggle:after {
      content: 'On';
      right: -4rem;
      opacity: .5;
    }*/
    
    .btn-toggle>.handle {
      position: absolute;
      top: 0.1875rem;
      left: 0.1875rem;
      width: 1.125rem;
      height: 1.125rem;
      border-radius: 1.125rem;
      background: #fff;
      transition: left .25s;
    }
    
    .btn-toggle.active {
      transition: background-color 0.25s;
    }
    
    .btn-toggle.active>.handle {
      left: 1.6875rem;
      transition: left .25s;
    }
    
    .btn-toggle.active:before {
      opacity: .5;
    }
    
    .btn-toggle.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-sm:before,
    .btn-toggle.btn-sm:after {
      line-height: -0.5rem;
      color: #fff;
      letter-spacing: .75px;
      left: 0.4125rem;
      width: 2.325rem;
    }
    
    .btn-toggle.btn-sm:before {
      text-align: right;
    }
    
    .btn-toggle.btn-sm:after {
      text-align: left;
      opacity: 0;
    }
    
    .btn-toggle.btn-sm.active:before {
      opacity: 0;
    }
    
    .btn-toggle.btn-sm.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-xs:before,
    .btn-toggle.btn-xs:after {
      display: none;
    }
    
    .btn-toggle:before,
    .btn-toggle:after {
      color: #6b7381;
    }
    
    .btn-toggle.active {
      background-color: #29b5a8;
    }
    
    .btn-toggle.btn-lg {
      margin: 0;
      padding: 0;
      position: relative;
      border: none;
      height: 2.5rem;
      width: 5rem;
      border-radius: 2.5rem;
    }
    
    .btn-toggle.btn-lg:focus,
    .btn-toggle.btn-lg.focus,
    .btn-toggle.btn-lg:focus.active,
    .btn-toggle.btn-lg.focus.active {
      outline: none;
    }
    
    .btn-toggle.btn-lg:before,
    .btn-toggle.btn-lg:after {
      line-height: 2.5rem;
      width: 5rem;
      text-align: center;
      font-weight: 600;
      font-size: 1rem;
      text-transform: uppercase;
      letter-spacing: 2px;
      position: absolute;
      bottom: 0;
      transition: opacity .25s;
    }
    
    
    /*.btn-toggle.btn-lg:before {
      content: 'Off';
      left: -5rem;
    }
    .btn-toggle.btn-lg:after {
      content: 'On';
      right: -5rem;
      opacity: .5;
    }*/
    
    .btn-toggle.btn-lg>.handle {
      position: absolute;
      top: 0.3125rem;
      left: 0.3125rem;
      width: 1.875rem;
      height: 1.875rem;
      border-radius: 1.875rem;
      background: #fff;
      transition: left .25s;
    }
    
    .btn-toggle.btn-lg.active {
      transition: background-color 0.25s;
    }
    
    .btn-toggle.btn-lg.active>.handle {
      left: 2.8125rem;
      transition: left .25s;
    }
    
    .btn-toggle.btn-lg.active:before {
      opacity: .5;
    }
    
    .btn-toggle.btn-lg.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-lg.btn-sm:before,
    .btn-toggle.btn-lg.btn-sm:after {
      line-height: 0.5rem;
      color: #fff;
      letter-spacing: .75px;
      left: 0.6875rem;
      width: 3.875rem;
    }
    
    .btn-toggle.btn-lg.btn-sm:before {
      text-align: right;
    }
    
    .btn-toggle.btn-lg.btn-sm:after {
      text-align: left;
      opacity: 0;
    }
    
    .btn-toggle.btn-lg.btn-sm.active:before {
      opacity: 0;
    }
    
    .btn-toggle.btn-lg.btn-sm.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-lg.btn-xs:before,
    .btn-toggle.btn-lg.btn-xs:after {
      display: none;
    }
    
    .btn-toggle.btn-sm {
      margin: 0 0.5rem;
      padding: 0;
      position: relative;
      border: none;
      height: 1.5rem;
      width: 3rem;
      border-radius: 1.5rem;
    }
    
    .btn-toggle.btn-sm:focus,
    .btn-toggle.btn-sm.focus,
    .btn-toggle.btn-sm:focus.active,
    .btn-toggle.btn-sm.focus.active {
      outline: none;
    }
    
    .btn-toggle.btn-sm:before,
    .btn-toggle.btn-sm:after {
      line-height: 1.5rem;
      width: 0.5rem;
      text-align: center;
      font-weight: 600;
      font-size: 0.55rem;
      text-transform: uppercase;
      letter-spacing: 2px;
      position: absolute;
      bottom: 0;
      transition: opacity .25s;
    }
    
    .btn-toggle.btn-sm:before {
      content: 'Off';
      left: -0.5rem;
    }
    
    .btn-toggle.btn-sm:after {
      content: 'On';
      right: -0.5rem;
      opacity: .5;
    }
    
    .btn-toggle.btn-sm>.handle {
      position: absolute;
      top: 0.1875rem;
      left: 0.1875rem;
      width: 1.125rem;
      height: 1.125rem;
      border-radius: 1.125rem;
      background: #fff;
      transition: left .25s;
    }
    
    .btn-toggle.btn-sm.active {
      transition: background-color 0.25s;
    }
    
    .btn-toggle.btn-sm.active>.handle {
      left: 1.6875rem;
      transition: left .25s;
    }
    
    .btn-toggle.btn-sm.active:before {
      opacity: .5;
    }
    
    .btn-toggle.btn-sm.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-sm.btn-sm:before,
    .btn-toggle.btn-sm.btn-sm:after {
      line-height: -0.5rem;
      color: #fff;
      letter-spacing: .75px;
      left: 0.4125rem;
      width: 2.325rem;
    }
    
    .btn-toggle.btn-sm.btn-sm:before {
      text-align: right;
    }
    
    .btn-toggle.btn-sm.btn-sm:after {
      text-align: left;
      opacity: 0;
    }
    
    .btn-toggle.btn-sm.btn-sm.active:before {
      opacity: 0;
    }
    
    .btn-toggle.btn-sm.btn-sm.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-sm.btn-xs:before,
    .btn-toggle.btn-sm.btn-xs:after {
      display: none;
    }
    
    .btn-toggle.btn-xs {
      margin: 0 0;
      padding: 0;
      position: relative;
      border: none;
      height: 1rem;
      width: 2rem;
      border-radius: 1rem;
    }
    
    .btn-toggle.btn-xs:focus,
    .btn-toggle.btn-xs.focus,
    .btn-toggle.btn-xs:focus.active,
    .btn-toggle.btn-xs.focus.active {
      outline: none;
    }
    
    .btn-toggle.btn-xs:before,
    .btn-toggle.btn-xs:after {
      line-height: 1rem;
      width: 0;
      text-align: center;
      font-weight: 600;
      font-size: 0.75rem;
      text-transform: uppercase;
      letter-spacing: 2px;
      position: absolute;
      bottom: 0;
      transition: opacity .25s;
    }
    
    .btn-toggle.btn-xs:before {
      content: 'Off';
      left: 0;
    }
    
    .btn-toggle.btn-xs:after {
      content: 'On';
      right: 0;
      opacity: .5;
    }
    
    .btn-toggle.btn-xs>.handle {
      position: absolute;
      top: 0.125rem;
      left: 0.125rem;
      width: 0.75rem;
      height: 0.75rem;
      border-radius: 0.75rem;
      background: #fff;
      transition: left .25s;
    }
    
    .btn-toggle.btn-xs.active {
      transition: background-color 0.25s;
    }
    
    .btn-toggle.btn-xs.active>.handle {
      left: 1.125rem;
      transition: left .25s;
    }
    
    .btn-toggle.btn-xs.active:before {
      opacity: .5;
    }
    
    .btn-toggle.btn-xs.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-xs.btn-sm:before,
    .btn-toggle.btn-xs.btn-sm:after {
      line-height: -1rem;
      color: #fff;
      letter-spacing: .75px;
      left: 0.275rem;
      width: 1.55rem;
    }
    
    .btn-toggle.btn-xs.btn-sm:before {
      text-align: right;
    }
    
    .btn-toggle.btn-xs.btn-sm:after {
      text-align: left;
      opacity: 0;
    }
    
    .btn-toggle.btn-xs.btn-sm.active:before {
      opacity: 0;
    }
    
    .btn-toggle.btn-xs.btn-sm.active:after {
      opacity: 1;
    }
    
    .btn-toggle.btn-xs.btn-xs:before,
    .btn-toggle.btn-xs.btn-xs:after {
      display: none;
    }
    
    .btn-toggle.btn-secondary {
      color: #6b7381;
      background: #bdc1c8;
    }
    
    .btn-toggle.btn-secondary:before,
    .btn-toggle.btn-secondary:after {
      color: #6b7381;
    }
    
    .btn-toggle.btn-secondary.active {
      background-color: #ff8300;
    }
    
    .btn-toggle.btn-secondary.active {
      background-color: #ff8300;
    }
    &#13;
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    
    <button type="button" class="report-sens-btn btn btn-lg btn-toggle" data-toggle="button" aria-pressed="true" autocomplete="off">
    <div class="handle"></div>
    </button>
    
    <a class="report-action-btn btn btn-icon waves-effect waves-light btn-success m-b-5">
      <i class="fa fa-thumbs-o-up"></i>
    </a>
    &#13;
    &#13;
    &#13;