淡出/淡出使DIV's堆叠而不是重叠?使用& # 39;绝对# 39;这不是一个解决方案
FadeIn / FadeOut make DIV's stack instead of overlapping? Using 'absolute' wasn't a solution
我目前正在使用以下代码来淡入/淡出各种div(保存信息)。这是有效的,但我不满意的结果。它们应该相互重叠,而不是相互堆积。
我做了一个搜索,对我来说唯一可行的事情是添加:position:absolute;在CSS中。虽然这是有效的,但它会把下面的其他项弄乱。所以我希望解决这个问题。
我确实读到插入一个所谓的回调函数,但是我不知道如何使用这个代码。
这是一段淡入/淡出代码:
$('.extraInfo').hide();
$('input').on('ifChecked', function(event){
var extraInformationId = $(this).closest('label')[0].id;
if(extraInformationId != undefined) {
$('div.extraInfo[data-extrainformationfor="' + extraInformationId+'"]').fadeIn(500);
}
});
$('input').on('ifUnchecked', function(event){
var extraInformationId = $(this).closest('label')[0].id;
if(extraInformationId != undefined) {
$('div.extraInfo[data-extrainformationfor="' + extraInformationId+'"]').fadeOut(500);
}
});
我自己能想到的最好的事情,除了将CSS更改为绝对,就是将淡入/淡出从500更改为0。然而,这并不是一个真正的解决方案。: |
如果你需要更多的信息和/或细节,这里是JSFiddle。
当你点击项目时,你会注意到DIV是堆叠的。在我看来,这让事情看起来有点"丑陋"。
删除ifUnchecked
部分,并将其用于ifChecked
$('input').on('ifChecked', function(event){
$("div.extraInfo")
.fadeOut(500) // hide all divs with class `extraInfo`
.promise() // "wait" for the asynchonous animations to complete
.done(function() { // and then show the info for the selected one
var extraInformationId = $(this).closest('label').attr("id");
if(extraInformationId) {
$('div.extraInfo[data-extrainformationfor="' + extraInformationId+'"]').fadeIn(500);
}
}.bind(this)); // preserve the value of this for the callback of fadeOut
});
小提琴
不要用fadeout
,用hide
$('input').on('ifUnchecked', function(event){
var extraInformationId = $(this).closest('label')[0].id;
if(extraInformationId != undefined) {
$('div.extraInfo[data-extrainformationfor="' + extraInformationId+'"]').hide();
}
});
我通过引入一些延迟使其工作。自从检查&取消检查几乎是同时发生的,你看到两个文本之前一个被删除
$('input').on('ifChecked', function(event){
var extraInformationId = $(this).closest('label')[0].id;
if(extraInformationId != undefined) {
setTimeout(function(){
$('div.extraInfo[data-extrainformationfor="' + extraInformationId+'"]').fadeIn(1000);
},1000)
}
});
[jsfiddle][1]
相关文章:
- 如何对单个页面进行密码保护(这不是身份验证系统的一部分)
- 为什么jQuery掩码说它'It’这不是函数
- NodeJS,通过socket控制台发送缓冲区后表示'这不是缓冲区
- 图像加载,IE中的另一个错误 - 相当确定这不是缓存错误
- Chrome 如何获取 gist json 文件?这不是被禁止的吗
- 如何将一个 JavaScript 文件包含在另一个 JavaScript 文件中 这不是从浏览器中运行的
- 为什么这不是一个javascript闭包
- 如何在下面修复此错误,说明这不是一个函数
- 我收到“这不是函数”错误
- 为什么这不是一个明确的整数类型,以及如何使其明确
- Uncaught TypeError:向Date原型添加函数时,这不是Date对象
- Jquery$(document).ready返回错误:“”;这不是一个函数;
- 为什么获胜'这不是我简单的Angular.js应用程序工作
- 为什么这不是有效的代码
- JQuery prettyPhoto-从'It’这不是图像
- TypeScript|扩展错误(未捕获的TypeError:这不是X对象)
- TypeError:这不是Date对象
- 指令绑定中的值是正确的,但它'It’’It’这不是真的
- 为什么不是'这不是谷歌地图的一个例子吗?InvalidValueError:setMap:不是Map;的实例;
- 淡出/淡出使DIV's堆叠而不是重叠?使用& # 39;绝对# 39;这不是一个解决方案