CSS 过渡重复?

标签 css css-transitions

我正在设计一个用户界面,您可以在其中选择特定对象。当您这样做时,会滑出一个信息 Pane 。一切正常,除非您在元素之间切换我希望动画再次运行。

这是完整的代码笔:http://codepen.io/ScottBeeson/pen/JGyDa

这是相关的 CSS:

#info.show {
    transition-property: all;
    transition-duration: .5s;
    transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
}

这是相关的 JS:

$('#items div').on('click', function() {
  $('#info').removeClass('show').addClass('show').html('Box ' + $(this).html() + ' is selected')
})

最佳答案

看起来删除类并没有像您预期的那样首先隐藏 div。您可以尝试使用 setTimeout 将类添加到 onclick 事件处理程序之外(在删除类之后):

$('#items div').on('click', function() {
  $('#info').removeClass('show');
  setTimeout(function(){
               $('#info').addClass('show')
                         .html('Box ' + $(this).html() + ' is selected')
            }.bind(this),1);
})

Updated demo.

某些旧浏览器可能不支持bind 方法,请尝试使用jQuery 的$.proxy 方法 Demo

关于CSS 过渡重复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24125477/

相关文章:

javascript - 相对于容器的字体大小

PHP : how to allow only registered users to go to another page

html - CSS3 列布局中元素的动画位置

javascript - 当发生多个转换时,如何检测 'specific' 元素上的 CSS 转换结束?

css-animations - Tailwind UI 过渡和变换

javascript - 在进入下一步之前强制 JavaScript 完成动画

CSS:重复背景位置?

html - Bootstrap li 填充 0 不工作

javascript - 不间断地为菜单的每个元素添加悬停时的声音

javascript - 单击时切换 CSS 样式