HTML5技术

css3加载ing动画 - 明lucky

字号+ 作者:H5之家 来源:H5之家 2016-12-19 13:00 我要评论( )

项目中ajax交互成功前总会需要给用户提醒,比如请稍候、正在加载中等等,那个等待的动图以前项目中用的是gif,在移动端画质很渣,有毛边,于是在新项目中用css3展示加载中的动画效果。 function tipLoading(type,top,left){ if ($("arrorbox"))$('#arrorbox'

项目中ajax交互成功前总会需要给用户提醒,比如请稍候、正在加载中等等,那个等待的动图以前项目中用的是gif,在移动端画质很渣,有毛边,于是在新项目中用css3展示加载中的动画效果。

function tipLoading(type,top,left){ if($("arrorbox"))$('#arrorbox').remove(); var dataType=[ '<div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>', '<div><div></div><div></div><div></div></div>', ], html="<div></div>", type = type || 0, top = top || "48%", left = left || "50%", timer= null; $("body").append(html); if($(".tiploading")){ $(".tiploading").css({ "margin-left": -20+"px", "left": left, "top": top }); !type==1?$(".tiploading").append(dataType[type]+"<div>请稍候</div>"):$(".tiploading").append(dataType[type]+"<div></div>"); } } function tipLoadingRemove(){ if($(".tiploading")){ $(".tiploading").remove(); } }

js放在项目公用里,样式放到公用样式里,调用的时候tipLoading(type,top,left),在ajax交互成功前调用,成功后调用tipLoadingRemove()移除,也可以加个超时,不过让删了,type现在只有两种,网上有很多种,可以再加自己需要的,默认第一种0,传个1就是第二种。top、left为位置。

css↓↓

.tiploading{width: 40px;height: 40px;background: rgba(0,0,0,.7);position:fixed;border-radius: 10px;z-index: 9999;} .tiploading .tiploading-con{position:absolute;bottom:10px;left:0;width: 100%;height: 20px;line-height: 20px;font-size: 12px;color:#fff;text-align: center;} .sk-circle {width: 30px;height: 30px;position: relative;top:5px;left:5px;} .sk-circle .sk-child {width: 100%;height: 100%;position: absolute;left: 0;top: 0;} .sk-circle .sk-child:before {content: '';display: block;margin: 0 auto;width: 15%;height: 15%;background-color: #fff;border-radius: 100%;-webkit-animation: sk-circleBounceDelay 1.2s infinite ease-in-out both;animation: sk-circleBounceDelay 1.2s infinite ease-in-out both;} .sk-circle .sk-circle2 {-webkit-transform: rotate(30deg);-ms-transform: rotate(30deg);transform: rotate(30deg); } .sk-circle .sk-circle3 {-webkit-transform: rotate(60deg);-ms-transform: rotate(60deg);transform: rotate(60deg); } .sk-circle .sk-circle4 {-webkit-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); } .sk-circle .sk-circle5 {-webkit-transform: rotate(120deg); -ms-transform: rotate(120deg); transform: rotate(120deg); } .sk-circle .sk-circle6 {-webkit-transform: rotate(150deg); -ms-transform: rotate(150deg); transform: rotate(150deg); } .sk-circle .sk-circle7 {-webkit-transform: rotate(180deg); -ms-transform: rotate(180deg); transform: rotate(180deg); } .sk-circle .sk-circle8 {-webkit-transform: rotate(210deg); -ms-transform: rotate(210deg); transform: rotate(210deg); } .sk-circle .sk-circle9 {-webkit-transform: rotate(240deg); -ms-transform: rotate(240deg); transform: rotate(240deg); } .sk-circle .sk-circle10 {-webkit-transform: rotate(270deg); -ms-transform: rotate(270deg); transform: rotate(270deg); } .sk-circle .sk-circle11 {-webkit-transform: rotate(300deg); -ms-transform: rotate(300deg); transform: rotate(300deg); } .sk-circle .sk-circle12 {-webkit-transform: rotate(330deg); -ms-transform: rotate(330deg); transform: rotate(330deg); } .sk-circle .sk-circle2:before {-webkit-animation-delay: -1.1s; animation-delay: -1.1s; } .sk-circle .sk-circle3:before {-webkit-animation-delay: -1s; animation-delay: -1s; } .sk-circle .sk-circle4:before {-webkit-animation-delay: -0.9s; animation-delay: -0.9s; } .sk-circle .sk-circle5:before {-webkit-animation-delay: -0.8s; animation-delay: -0.8s; } .sk-circle .sk-circle6:before {-webkit-animation-delay: -0.7s; animation-delay: -0.7s; } .sk-circle .sk-circle7:before {-webkit-animation-delay: -0.6s; animation-delay: -0.6s; } .sk-circle .sk-circle8:before {-webkit-animation-delay: -0.5s; animation-delay: -0.5s; } .sk-circle .sk-circle9:before {-webkit-animation-delay: -0.4s; animation-delay: -0.4s; } .sk-circle .sk-circle10:before {-webkit-animation-delay: -0.3s; animation-delay: -0.3s; } .sk-circle .sk-circle11:before {-webkit-animation-delay: -0.2s; animation-delay: -0.2s; } .sk-circle .sk-circle12:before {-webkit-animation-delay: -0.1s; animation-delay: -0.1s; } @-webkit-keyframes sk-circleBounceDelay {0%, 80%, 100% {-webkit-transform: scale(0); transform: scale(0); } 40% {-webkit-transform: scale(1); transform: scale(1); } } @keyframes sk-circleBounceDelay {0%, 80%, 100% {-webkit-transform: scale(0); transform: scale(0); } 40% {-webkit-transform: scale(1); transform: scale(1); } } .spinner {margin: 10px auto ;width: 40px;text-align: center;} .spinner > div {width: 8px;height: 8px;background-color: #fff;border-radius: 100%;display: inline-block;-webkit-animation: sk-bouncedelay 1.4s infinite ease-in-out both;animation: sk-bouncedelay 1.4s infinite ease-in-out both;} .spinner .bounce1 {-webkit-animation-delay: -0.32s;animation-delay: -0.32s;} .spinner .bounce2 {-webkit-animation-delay: -0.16s;animation-delay: -0.16s;} @-webkit-keyframes sk-bouncedelay {0%, 80%, 100% { -webkit-transform: scale(0) } 40% { -webkit-transform: scale(1.0) } } @keyframes sk-bouncedelay {0%, 80%, 100% {-webkit-transform: scale(0); transform: scale(0); } 40% {-webkit-transform: scale(1.0); transform: scale(1.0); } }

type1

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • react动画难写?试试react版transformjs - 【当耐特】

    react动画难写?试试react版transformjs - 【当耐特】

    2016-12-19 14:00

  • 第一个随笔,调试中,用的CSS3 - TheWinds

    第一个随笔,调试中,用的CSS3 - TheWinds

    2016-12-17 12:01

  • Three.js外部模型加载 - CQ-engineer

    Three.js外部模型加载 - CQ-engineer

    2016-12-13 10:00

  • HTML5 与 CSS3 jQuery部分知识总结 - 细数逝去的过往

    HTML5 与 CSS3 jQuery部分知识总结 - 细数逝去的过往

    2016-12-12 15:00

网友点评