之前通过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效果的更多相关文章

  1. ajax加载菊花loading效果

    Ajax异步请求的时候,一般都会利用一个动态的gif小图片来制作一个Ajax Loading,以便增加用户体验. 这里我们可以使用Spin.js,该js脚本压缩后5k,可以不用任何图片,任何外部CSS ...

  2. 页面加载时loading效果

    页面加载时loading效果: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...

  3. Ajax全局加载框(Loading效果)的配置

    在Ajax进行后台数据请求的过程中,我们有时候会希望用户能知道页面后台还在做一些事情,这时候就需要给用户一个非常明确的提示,也就是我们所谓的进度条 废话完成~ 实现原理: Jquery可以对ajax进 ...

  4. jquery mobile在页面加载时添加加载中效果 document.ready 和window.onload执行顺序比较

    想要添加这个效果,先来弄明白页面的加载和事件执行顺序,看这个简单例子: <html xmlns="http://www.w3.org/1999/xhtml"> < ...

  5. ajax加载时的进度条

    运行效果如下图,pc和移动都可以展示,调用方法很简单,开始调用:loading.baosight.showPageLoadingMsg(false),false代表不现实加载说明,true展示加载说明 ...

  6. CSS3——制作正在加载页面loading...

    今天做了好多小东西,还挺开心的~ <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  7. Ajax加载菊花loding效果

    Ajax 异步请求的时候,一般都会利用一个动态的 gif小图片来制作一个Ajax Loading ,以便增加用户体验. 这里我们使用Spin.js ,该 js 脚本压缩后5k,可以不用任何图片,任何外 ...

  8. Android进度加载的Loading效果

    网上看到的一个开源项目的loading效果,效果很赞,记录一下: 开源项目地址如下:https://github.com/RomainPiel/Titanic

  9. 全局Ajax加载时呈现Loading

    全局设置: 1 2 3 4 5 $(document).bind("ajaxSend", function () {         $("#loading_messag ...

随机推荐

  1. 如何理解精通PHP ?

    「精通 PHP」可以理解为以下三个: 精通「PHP 解析器 精通「PHP 语法.函数(这门语言) 精通「PHP 项目开发 1 精通「PHP 解析器」 可以从这里开始学习: PHP核心:骇客指南 :ht ...

  2. 手动把第三方的jar包添加到本地mavne仓库的方法

    在实际实用maven进行开发的过程中,有一些项目没有使用maven来进行打包(比如我在做中文分词时候用的IK分词器),我们就无法在maven的仓库中下载这些jar包,但是我们在开发中会用到这些东西,所 ...

  3. 【BZOJ4428】[Nwerc2015]Debugging调试 记忆化搜索+分块

    [BZOJ4428][Nwerc2015]Debugging调试 Description 你看中的调试器将不会在这件事上帮助你.有代码可以通过多种方式在调试与正式发布的间隙发生不同的行为,当出现这种情 ...

  4. android去除Spinner的分割线

    <style name="TestSpinnerStyle" parent="android:style/Widget.ListView.DropDown" ...

  5. angularJs初体验,实现双向数据绑定!使用体会:比较爽

    使用初体验:ng 双向数据绑定: 最简单的双向数据绑定:(使用默认模块控制) <body ng-app> <input type="text" ng-model= ...

  6. Oracle自动备份脚本的实现

    问题描述: Oracle自动备份脚本的实现. 错误提示1: Message file RMAN.msb not found Verify that Oracle_HOME is set properl ...

  7. 9.SQL存储过程实例详解

    本文用3个题目,从建立数据库到创建存储过程,详细讲解数据库的功能. 题目1 学校图书馆借书信息管理系统建立三个表:学生信息表:student 字段名称 数据类型 说明 stuID char(10) 学 ...

  8. pta 习题集5-6 堆栈操作合法性

    假设以S和X分别表示入栈和出栈操作.如果根据一个仅由S和X构成的序列,对一个空堆栈进行操作,相应操作均可行(如没有出现删除时栈空)且最后状态也是栈空,则称该序列是合法的堆栈操作序列.请编写程序,输入S ...

  9. network command assistant

    这篇文章收集了久经考验靠谱的命令,也收集了几个比较新的命令.多数命令都可以在图形桌面执行,即使是没什么终端使用经验的Linux用户也会常常执行命令来使用ping或是其它的网络诊断工具. 1.curl ...

  10. UIWebView中加载的网页尺寸太大,如何让网页适应屏幕大小 WebView加载HTML图片大小自适应与文章自动换行

    webview.scalesPageToFit = YES; http://www.cnblogs.com/yujidewu/p/5740934.html 若需要根据图片原本大小,宽度小于320px的 ...