Jus*_*tin 2 javascript css ajax jquery css3
我试图为包含许多AJAX请求的页面显示加载图像(并将父透明化).为每个div独立添加/删除加载图标和不透明度最有效的方法是什么?
这是我到目前为止所拥有的.我的方法的问题是不透明度也应用于gif,这不是我想要的.是否可以轻松修复我的代码或更好的方法?
示例:http://jsfiddle.net/justincook/x4C2t/
HTML:
<div id="a" class="box">A</div>
<div id="b" class="box">B</div>
<div id="c" class="box">C</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$.fn.loading = function(show){
if(show){
this.prepend('<div class="loading-centered"></div>');
this.css({ opacity: 0.3 });
}else{
this.children('.loading-centered').remove();
this.css({ opacity: 1 });
}
};
$('#a').loading(true); //start
setTimeout(function(){ $('#a').loading(false); }, 3000); // stop
Run Code Online (Sandbox Code Playgroud)
小智 5
我会在CSS中保留样式,只需使用JS注入/删除元素http://jsfiddle.net/x4C2t/7/
$.fn.loading = function(show){
if(show){
this.prepend('<div class="loading-centered"></div>');
}else{
this.children('.loading-centered').remove();
}
};
Run Code Online (Sandbox Code Playgroud)
CSS:
.box {
float:left;
width:100px;
height:100px;
border:1px solid #bbb;
margin: 10px;
padding:20px;
text-align:center;
border-radius:10px;
background: #eee;
position: relative;
}
.loading-centered {
background:url('http://www.ajaxload.info/images/exemples/24.gif') center center no-repeat white;
position:absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
border-radius:10px;
zoom: 1;
filter: alpha(opacity=50);
opacity: 0.5;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3172 次 |
| 最近记录: |