自己突发奇想,想为wordpress大前端的主题添加一个加载进度条,在网上查看了一些资料都不是我想要的,这里用到的其实也很简单就用了CSS3+JQ,话不多少开始上教程。
只试用与大前端主题 ,其他主题可以修改JS代码。
CSS代码部分
可以放到style.css也可以放到css目录里的mian.css里。
@keyframes loading-bar-move{0%{width:0;opacity:0}%{width:0;opacity:0}70%{width:100%;opacity:1}100%{width:100%;opacity:0}} @-moz-keyframes loading-bar-move{0%{width:0;opacity:0}70%{width:100%;opacity:1}100%{width:100%;opacity:0}} @-o-keyframes loading-bar-move{0%{width:0;opacity:0}70%{width:100%;opacity:1}100%{width:100%;opacity:0}} @-webkit-keyframes loading-bar-move{0%{width:0;opacity:0}70%{width:100%;opacity:1}100%{width:100%;opacity:0}} .progress{border-radius: 0;position: absolute;left:0;top:0;height:5px;animation:loading-bar-move 2s;-moz-animation:loading-bar-move 2s;-webkit-animation:loading-bar-move 2s;-o-animation:loading-bar-move 2s;} .progress-bar{width:100%;}
JQ代码
可以放到JS文件夹里面的main.js里,当然如果自己为了区分开来,也可以自己建一个新的js文件,然后在网页底部引入即可。
//进度条加载! $(document).on("click","a",function(){ if( $(window).width()<768 ) return; if( $(this).attr('target')=='_blank' ) return; if( $(this).parent('#pagination-comments').length>0 ) return; var url = $(this).attr('href'); var u = document.createElement('a'); u.href = url, ru = u.protocol+u.hostname+u.pathname+u.search, l = location, rl = l.protocol+l.hostname+l.pathname+l.search; if(ru==rl) return; var urlreg=/^((https|http|ftp|rtsp|mms)?:\/\/)+[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/; if(urlreg.test(url)){ n = $('.header'); if( n.children('.progress').length<=0 ){ n.prepend('<div class="progress"><div class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar"></div></div>'); } } });
阅读全文
评论前必须登录!
立即登录 注册