JQuery+CSS3实现Ajax加载时loading效果
之前通过Ajax请求加载数据的时候,在数据还没有呈现出来前,为了更好的用户体验,总会弄个loading告诉用户其实内容正在加载,而不是网站崩了。但是貌似之前使用gif图片的情况比较多,可能是为了兼容各个浏览器,但是CSS3已经很强大到我们可以自己使用动画写出一个loading效果出来,然后再通过调用JQuery的ajaxStart()和ajaxStop()这两个事件处理函数,就可以实现我们想要的loading效果了。
这里主要介绍一个CSS3 loading的网站:http://cssload.net/ ,通过使用这个网站,我们可以通过几步就轻松地使用CSS3完成我们想要的loading效果,然后一键获得代码:

比如,在这里我选择了这样一个效果,然后点击GET CODE 按钮,就可以得到代码:
#fountainG{
position:relative;
margin:10% auto;
width:240px;
height:29px}
.fountainG{
position:absolute;
top:;
background-color:#33cc99;
width:29px;
height:29px;
-webkit-animation:bounce_fountainG 1.3s infinite normal;
-moz-animation:bounce_fountainG 1.3s infinite normal;
-o-animation:bounce_fountainG 1.3s infinite normal;
-ms-animation:bounce_fountainG 1.3s infinite normal;
animation:bounce_fountainG 1.3s infinite normal;
-moz-transform:scale(.3);
-webkit-transform:scale(.3);
-ms-transform:scale(.3);
-o-transform:scale(.3);
transform:scale(.3);
border-radius:19px;
}
#fountainG_1{
left:;
-moz-animation-delay:0.52s;
-webkit-animation-delay:0.52s;
-ms-animation-delay:0.52s;
-o-animation-delay:0.52s;
animation-delay:0.52s;
}
#fountainG_2{
left:30px;
-moz-animation-delay:0.65s;
-webkit-animation-delay:0.65s;
-ms-animation-delay:0.65s;
-o-animation-delay:0.65s;
animation-delay:0.65s;
}
#fountainG_3{
left:60px;
-moz-animation-delay:0.78s;
-webkit-animation-delay:0.78s;
-ms-animation-delay:0.78s;
-o-animation-delay:0.78s;
animation-delay:0.78s;
}
#fountainG_4{
left:90px;
-moz-animation-delay:0.91s;
-webkit-animation-delay:0.91s;
-ms-animation-delay:0.91s;
-o-animation-delay:0.91s;
animation-delay:0.91s;
}
#fountainG_5{
left:120px;
-moz-animation-delay:1.04s;
-webkit-animation-delay:1.04s;
-ms-animation-delay:1.04s;
-o-animation-delay:1.04s;
animation-delay:1.04s;
}
#fountainG_6{
left:150px;
-moz-animation-delay:1.17s;
-webkit-animation-delay:1.17s;
-ms-animation-delay:1.17s;
-o-animation-delay:1.17s;
animation-delay:1.17s;
}
#fountainG_7{
left:180px;
-moz-animation-delay:1.3s;
-webkit-animation-delay:1.3s;
-ms-animation-delay:1.3s;
-o-animation-delay:1.3s;
animation-delay:1.3s;
}
#fountainG_8{
left:210px;
-moz-animation-delay:1.43s;
-webkit-animation-delay:1.43s;
-ms-animation-delay:1.43s;
-o-animation-delay:1.43s;
animation-delay:1.43s;
}
@-moz-keyframes bounce_fountainG{
0%{
-moz-transform:scale(1);
background-color:#33cc99;
}
100%{
-moz-transform:scale(.3);
background-color:#0099cc;
}
}
@-webkit-keyframes bounce_fountainG{
0%{
-webkit-transform:scale(1);
background-color:#33cc99;
}
100%{
-webkit-transform:scale(.3);
background-color:#0099cc;
}
}
@-ms-keyframes bounce_fountainG{
0%{
-ms-transform:scale(1);
background-color:#33cc99;
}
100%{
-ms-transform:scale(.3);
background-color:#0099cc;
}
}
@-o-keyframes bounce_fountainG{
0%{
-o-transform:scale(1);
background-color:#33cc99;
}
100%{
-o-transform:scale(.3);
background-color:#0099cc;
}
}
@keyframes bounce_fountainG{
0%{
transform:scale(1);
background-color:#33cc99;
}
100%{
transform:scale(.3);
background-color:#0099cc;
}
}
同时也包含html结构:
<div id="fountainG">
<div id="fountainG_1" class="fountainG">
</div>
<div id="fountainG_2" class="fountainG">
</div>
<div id="fountainG_3" class="fountainG">
</div>
<div id="fountainG_4" class="fountainG">
</div>
<div id="fountainG_5" class="fountainG">
</div>
<div id="fountainG_6" class="fountainG">
</div>
<div id="fountainG_7" class="fountainG">
</div>
<div id="fountainG_8" class="fountainG">
</div>
</div>
最后,将html结构放在比如文章列表或者其他需要Ajax请求加载的地方,然后使用JQuery来实现最终的效果:
function loadingEffect() {
var loading = $('#fountainG');
loading.hide();
$(document).ajaxStart(function () {
loading.show();
}).ajaxStop(function () {
loading.hide();
});
}
loadingEffect();
这样就完成了,具体喜欢哪个loading效果,该网站提供了十几种效果,已经够用了。当然如果你觉得这些效果很简单,也完全可以自己写出来,但对于我这种菜鸟,直接拿来用确实挺方便,效率高,而且还可以读一下源码,给自己一些想法。最后,CSS3实现loading效果确实挺nice,但如果要兼容浏览器的话,最好使用渐进增强方法来实现,确保低版本依旧可以使用gif图片代替。
JQuery+CSS3实现Ajax加载时loading效果的更多相关文章
- ajax加载菊花loading效果
Ajax异步请求的时候,一般都会利用一个动态的gif小图片来制作一个Ajax Loading,以便增加用户体验. 这里我们可以使用Spin.js,该js脚本压缩后5k,可以不用任何图片,任何外部CSS ...
- 页面加载时loading效果
页面加载时loading效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- Ajax全局加载框(Loading效果)的配置
在Ajax进行后台数据请求的过程中,我们有时候会希望用户能知道页面后台还在做一些事情,这时候就需要给用户一个非常明确的提示,也就是我们所谓的进度条 废话完成~ 实现原理: Jquery可以对ajax进 ...
- jquery mobile在页面加载时添加加载中效果 document.ready 和window.onload执行顺序比较
想要添加这个效果,先来弄明白页面的加载和事件执行顺序,看这个简单例子: <html xmlns="http://www.w3.org/1999/xhtml"> < ...
- ajax加载时的进度条
运行效果如下图,pc和移动都可以展示,调用方法很简单,开始调用:loading.baosight.showPageLoadingMsg(false),false代表不现实加载说明,true展示加载说明 ...
- CSS3——制作正在加载页面loading...
今天做了好多小东西,还挺开心的~ <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- Ajax加载菊花loding效果
Ajax 异步请求的时候,一般都会利用一个动态的 gif小图片来制作一个Ajax Loading ,以便增加用户体验. 这里我们使用Spin.js ,该 js 脚本压缩后5k,可以不用任何图片,任何外 ...
- Android进度加载的Loading效果
网上看到的一个开源项目的loading效果,效果很赞,记录一下: 开源项目地址如下:https://github.com/RomainPiel/Titanic
- 全局Ajax加载时呈现Loading
全局设置: 1 2 3 4 5 $(document).bind("ajaxSend", function () { $("#loading_messag ...
随机推荐
- poj_3258 二分法
题目大意 给定区间[0,L],在区间内给定N个数,加上区间的端点总共N+2个值.这N+2个数相邻的两个数之间有一个差值delta[i],现在可以从除去端点之外的这N个数中删除M个,使得剩余的N+2-M ...
- webpack之跨域
前后端分离开发中,本地前端开发调用接口会有跨域问题,一般有以下几种解决方法: 直接启动服务端项目,再将项目中的资源url指向到前端服务中的静态资源地址,好处在于因为始终在服务端的环境中进行资源调试,不 ...
- 使用openssl生成RSA公钥和私钥对
在ubuntu上要使用openssl的话需要先进行安装,命令如下: sudo apt-get install openssl 安装完成就可以使用openssl了. 首先需要进入openssl的交互界面 ...
- 360全景图three.js
1.three.js是JavaScript编写的WebGL第三方库.提供了非常多的3D显示功能. Three.js 是一款运行在浏览器中的 3D 引擎,你可以用它创建各种三维场景,包括了摄影机.光影. ...
- 【BZOJ2595】[Wc2008]游览计划 斯坦纳树
[BZOJ2595][Wc2008]游览计划 Description Input 第一行有两个整数,N和 M,描述方块的数目. 接下来 N行, 每行有 M 个非负整数, 如果该整数为 0, 则该方块为 ...
- Android dialog 全屏
Android中让Dialog全屏: 一.在style中定义样式: <?xml version="1.0" encoding="utf-8"?> & ...
- 几种常用的SQL优化工具及方法
转自:http://blog.itpub.net/35489/viewspace-764856/ 1. sql 详细执行计划,主要检查驱动路径,索引是否合适:同一个pl/sql窗口连续执行即可:exp ...
- matplotlib 散点图scatter
最近开始学习python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...
- Yii 后台防止表单提交
第一种方法: 在AR类中设置rules()方法里面设置该属性为unique属性 Class Item extends \yii\db\ActiveRecord{ public function rul ...
- V2EX的RSS订阅地址
1.全站RSS输出: https://www.v2ex.com/index.xml 2.单独节点RSS输出: http://www.v2ex.com/feed/{节点名}.xml 以shadowso ...