根据页面长度实现阅读进度条,具体看页面上的效果。
- ;(function(w,d){
- var dom = d.createElement(‘div’);
- dom.className = ‘scrollMove’;
- dom.style.cssText = ‘position: fixed; left: 0px; top: 0px; height: 7px; background: #f00808; z-index: 999999;box-shadow: 0px 0px 3px #999;width: 0;transition:width 0.3s ease-out;-moz-transition:width 0.3s ease-out;-webkit-transition:width 0.3s ease-out;’
- d.body.appendChild(dom);
- w.addEventListener(‘scroll’,function(){
- dom.style.width = Math.round((pageYOffset / (d.body.offsetHeight – d.documentElement.clientHeight)) * 100) +’%’;
- },false);
- })(window,document);