【发布时间】:2014-09-25 14:12:35
【问题描述】:
我正在尝试在单击链接时打开隐藏在幻灯片中的内容。
我有一个关键帧动画,用于尝试将高度从 0px 设置为 100%。第一次单击删除了.sr-only 类并添加了应该运行关键帧动画的.open 类。我不确定为什么关键帧动画不起作用。
到目前为止,这是我的代码的一个小提琴:http://jsfiddle.net/JkaAL/
这是代码:请注意,我只是使用 -webkit- 前缀并仅在 chrome 中进行测试。
HTML:
<a href="#" class="js-link">Click Here</a>
<div class="js-content sr-only">
<p>Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test Test</p>
</div>
CSS:
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0 0 0 0);
border: 0;
}
@-webkit-keyframes openIt {
0% { height: 1px; }
100% { height: 100%; }
}
.open {
position: static;
width: auto;
padding: initial;
margin: initial;
overflow: visible;
clip: auto;
border: 0;
-webkit-animation: openIt 2s linear;
}
JavaScript:
var $link = $('.js-link'),
$content = $('.js-content');
$link.click(function(e) {
e.preventDefault();
if ( $content.hasClass('sr-only') ) {
$content.removeClass('sr-only').addClass('open');
}
else if ( $content.hasClass('open') ) {
$content.removeClass('open').addClass('sr-only');
}
});
【问题讨论】:
标签: javascript css animation css-animations