【发布时间】:2015-01-13 00:55:32
【问题描述】:
我正在尝试创建一个带有display: none 一些基于其类的元素的小菜单的平铺墙。在我的 CSS 中,我的 CSS 转换导致 fadeIn 和 fadeOut 不起作用。如果我添加时间,元素将需要很长时间才能消失,但没有实际的褪色。
CSS:
.block:not(.noTransition), .block a img, #main_side p, #main_content, #menu_container{
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 1s ease-in-out;
-o-transition: all 1s ease-in-out;
-ms-transition: all 1s ease-in-out;
transition: all 1s ease-in-out;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
使用 jQuery 的 JavaScript:
$(document).ready(function(){
$('.button').not("#all").click(function(){
var theId = $(this).attr('id');
$('.block').not('.'+theId).addClass("noTransition");
$('.block').not('.'+theId).fadeOut('slow', function(){
$('.block').not('.'+theId).addClass("covered");
$('.block').not('.'+theId).removeClass("noTransition");
});
$('.'+theId).addClass("noTransition");
$('.'+theId).fadeIn('slow',function(){
$('.'+theId).removeClass("covered");
$('.'+theId).removeClass("noTransition");
});
getScreenSize();
});
$("#all").click(function(){
$('.block').removeClass("covered");
$('.block').show();
});
getScreenSize();
});
如果我从我的 CSS 中删除过渡,淡入淡出确实有效,但我也想保留过渡以在元素被显示/隐藏后重新定位它们。
【问题讨论】:
-
我会尝试这样的事情:让你的 jQuery 代码在元素完成后添加一个 CSS 类(
enable-transitions或其他东西)。将 CSS 过渡附加到.block.enable-transitions等(反之亦然,让 jQuery 添加一个类以在您淡化元素时阻止过渡,并在 CSS 中使用:not(),如果您想在元素上启用过渡 jQuery从不使用。) -
尽管现在有一些新的不同的错误,但它确实有效!所以现在我在褪色发生时禁用缓动,然后再次允许缓动。谢谢!