我看过其他问题,似乎没有人和我有同样的问题,这总是很令人兴奋!
当您到达页面时,我试图对我的页面内容进行整洁的观察。一切都被CSS封锁了。点击的大链接可删除所有编辑效果。我已经成功地使jQuery删除了编辑样式类,但它根本没有动画。我正在使用jQuery UI库。我看到有人提到它不适用于!important
属性,无论有没有差别,没有!important
我无法覆盖属性。
请帮助obiwan,你是我唯一的希望!
**注意,我正在尝试使用JQuery UI能力而不是直接Jquery **
效果示例:http://api.jqueryui.com/removeClass/
Jquery
$(document).ready(function(){
$("#educate").addClass("redactedtext redactedblocks" );
$("#join").click(function() {
$("#educate").removeClass("redactedtext redactedblocks", 1000 );
$('#join').contents().unwrap();
});
});
和PHP /正文
<article class="row">
<article class="twelve columns mastblock predacted " id="make">
<p><a href="#" id="join">Join</a> us in making a <strong>new</strong> kind of documentary</p>
</article>
</article>
<section class="row " data-match-height >
<article class="radius-top-left medium-4 columns mastblock " id="educate">
<h1>Educational</h1>
<p>Find out what is behind the actions that lead to slavery, human trafficking, and forced Labour. Have a more complete picture on why slavery still exsists.</p>
<p>Learn more…</p>
</article>
预期的操作是点击按钮,看到停电消失,颜色再回来。
答案 0 :(得分:1)
是的,如果某个类具有我刚刚测试过的!important
属性,则无法为其设置动画。这里有2个小提琴,可以证明这一点。
!重要演示:http://jsfiddle.net/eaPcv/
正常演示:http://jsfiddle.net/eaPcv/1/
所以你运气不好。
但是说你必须使用!important
,否则样式将无法正常工作。当然有可能在没有使用!important
的情况下建立一个网站,并且看到你有很多!important
然后你正在编写错误的代码并且你在某处做错了。
答案 1 :(得分:1)
CSS动画为这个问题提供了更多功能的解决方案。适用于所有主流浏览器(有一些警告......)
这里的例子,基于我认为你想要实现的目标......
http://jsfiddle.net/adrianjmartin/xLpft/
<style>
.redacted {
background-color:black;
color:black;
}
@keyframes unredact{
to{
background-color:white;
}
}
@-webkit-keyframes unredact{
to{
background-color:white;
}
}
</style>
<script>
window.addEventListener( "load" , function(){
var p = document.querySelectorAll("P");
for( var ii = 0 ; ii < p.length ; ii++ ){
var t = p[ii].textContent;
var a = t.split( ' ' );
var h = "";
for( var i = 0 ; i < a.length ; i++ ){
h += "<span class='redacted'>"+a[i]+" </span>";
}
p[ii].innerHTML = h ;
}
});
window.addEventListener( "click" , function(){
var spans = document.querySelectorAll( "P span.redacted");
for( var i = 0; i < spans.length ; i++ ){
var delay = Math.random(3);
var delay = Math.random(3);
var style = "-webkit-animation: unredact forwards 3s " + delay + "s;";
style += "animation: unredact forwards 3s " + delay + "s";
}
});
</script>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce quis fringilla nisi. Curabitur vitae mi ultrices nunc sodales sodales at eget est. Aenean placerat eleifend lorem sed congue. Vivamus rutrum mi tempus leo interdum, vel volutpat velit consequat. Pellentesque eu sem metus. Nullam quis mauris ultrices augue blandit consequat. Vestibulum sollicitudin odio sed lobortis lacinia. Vivamus semper est et sapien ultrices, non vestibulum sapien tincidunt. Vivamus nunc neque, tincidunt ut arcu quis, bibendum hendrerit odio. Suspendisse id molestie ligula. Nulla dapibus venenatis tellus, egestas imperdiet velit pretium pellentesque. Mauris risus nibh, feugiat et magna sit amet, malesuada sagittis tellus. Curabitur porta, turpis ac tincidunt pharetra, augue est sodales ipsum, vitae pharetra eros nisl nec ante. Duis mattis volutpat est, in hendrerit urna mattis sed.<p>
<p>In bibendum nisl sit amet libero tempus ullamcorper. Vivamus a augue scelerisque, fermentum lorem et, vehicula justo. Praesent aliquet venenatis libero eget bibendum. Nam imperdiet fermentum libero et sagittis. Fusce varius posuere arcu, convallis varius ante aliquam ac. Proin eu nisi commodo, interdum erat vitae, iaculis massa. Fusce quis elit ac lacus viverra adipiscing. In hac habitasse platea dictumst. Sed sodales mauris non condimentum ultricies. Maecenas at venenatis arcu. Vestibulum scelerisque lacinia libero, eu tincidunt diam egestas eu. Suspendisse eu eros nulla. Ut dignissim nisl sed turpis tristique aliquam.
</p>