简体   繁体   English

图形按钮上的持久CSS3过渡效果

[英]Persistent CSS3 transition effect on graphic Button

I am kinda new to web development, and I would like to create a graphic button with a highlight pulsed effect, let me explain : 我是Web开发的新手,我想创建一个带有高亮脉冲效果的图形按钮,让我解释一下:

The button is built with 2 layers, the first is the default state always displayed, and the second layer is the highlighted state (white) displayed only when the button is clicked or touched (opacity of this layer is 1 when displayed, 0 when hidden). 该按钮由两层组成,第一层是始终显示的默认状态,第二层是仅在单击或触摸按钮时显示的突出显示状态(白色)(该层的不透明度在显示时为1,在隐藏时为0) )。

My problem is that I would like the opacity of the highlight to go from 0 to 1 regardless the duration of the click or the touch event. 我的问题是,无论单击或触摸事件的持续时间如何,我都希望高亮显示的不透明度从0变为1。 The transition back to opacity 0 value should occur only when value 1 has been reached, that means that release events (mouseup or touchend) shouldn't be triggered until the opacity of the hightlight layer has reached 1. 仅当达到值1时,才发生向不透明度0值的过渡,这意味着在高光层的不透明度达到1之前,不应该触发释放事件(鼠标或触摸结束)。

I am using Compass (scss) and jquery mobile with phonegap encapsulation. 我正在使用带电话间隙封装的Compass(s​​css)和jquery mobile。

I have coded a version which works, but doesn't meet my goal : The transition to highlighted state is stopped as soon as I release the button (for instance, if I make a very quick touch, even with a 0.2s transition on opacity, the highlighted state is not visible, though the touchend event is triggered... (the transition returns to 0 before reaching 1)... 我已经编码了一个可以使用的版本,但是不符合我的目标:释放按钮后,就会停止向突出显示状态的转换(例如,如果触摸非常快,即使不透明度转换为0.2s,也会立即停止) ,虽然触发了touchend事件,但突出显示的状态是不可见的(转换在达到1之前返回0)...

The whole code maybe not so clean, but I am trying to learn :) 整个代码可能不太干净,但是我正在尝试学习:)

Any clue or advice is welcome! 任何线索或建议都欢迎!

the HTML code looks like this : HTML代码如下所示:

<div class=btn-test>
 <span>
  <a class=btn-a href=#>
  </a>
 </span>
</div

the SCSS looks like this : SCSS看起来像这样:

@import "compass/reset";
@import "compass/css3";

.btn-test {

  span {
      @include background-image(image-url("foo.png"));
      background-position: 0px 0px;

      width: 72px;
      height: 70px;

      display: inline-block;
    }

  a {
      @include background-image(image-url("foo.png"));
      background-position: 0 71px;

      @include transition-property(opacity);
      @include transition-duration(0.2s);
      @include transition-timing-function(ease);  

      width: 72px;
      height: 70px;

      display: inline-block;

      -webkit-touch-callout: none !important; 
  }

  .btn-a {

    opacity: 0;
  }

  .btn-a:active {

    opacity: 1;
  }

}

What you want is an animation, not a simple transition. 您想要的是动画,而不是简单的过渡。 You get cross browser animation in compass 0.13 alpha with gem install compass --pre 您会在使用gem install compass --pre指南针0.13 alpha中获得跨浏览器动画

The solution would be to add keyframes for your different states : 解决方案是为您的不同状态添加关键帧:

@import "compass/css3/animation";

@include keyframes(flashButton){
  0%{
    opacity: 0;
  }
  50%{
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.animate-button {
  @include animate(flashButton 1s ease);
}

And then with a little bit of jQuery : 然后用一点jQuery:

$('.btn-test').on('click', function(){
  //reset state in case animation has already been played
  $('.btn-test').removeClass('animate-button');
  setTimeout(function(){$('.btn-test').addClass('animate-button')}, 1)
});

I didn't use it yet but you can also use https://github.com/ericam/compass-animate which is a compass port of the great css animations found here http://daneden.me/animate/ 我还没有使用过它,但您也可以使用https://github.com/ericam/compass-animate ,它是http://daneden.me/animate/上出色的CSS动画的指南针端口

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

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