前端预加载gif
內容描述待補充~
<!-- 頭部gif背景圖 S --><div id="Header":style="`height:${H};`"class="Header"><img id="headersBgGif"data-up="https://f2.kkmh.com/20200417tm.gif"src="https://f2.kkmh.com/20200424tm.gif" style="display: none;"><img id="header_bg_img"src="~assets/img/pd/contest/header_bg.png" style="display: block;"></div><!-- 頭部gif背景圖 E --> initHeight(){const _this = this;//1598[設計圖高度]*(headers.offsetWidth[獲取的實際寬度] / 2560[設計圖的寬度]) = 實際高度const Diffuse = document.getElementById('Diffuse');const W = Diffuse ? Diffuse.offsetWidth : 0;const num = W / 2560 > 1 ? 1 : W / 2560;this.setDiffuseRatio( num ); //存儲到vux 中的寬度實際比率this.H = Math.ceil( 1598 * this.diffuseRatio ) + 'px';console.log('h', this.H)// debugger;const headersBgGif = document.getElementById('headersBgGif');const headersBgImg = document.getElementById('header_bg_img');//判斷圖片是否加載完成if(!headersBgGif){return false;}let imgs = new Image;imgs.src = headersBgGif.src;imgs.onload = function() {if (headersBgImg) {headersBgGif.parentNode.removeChild(headersBgImg);}headersBgGif.style.display = 'block'};imgs.onerror = function(){console.error('頭部gif 加載失敗,請刷新重試!');}},總結
- 上一篇: 《转》CXF WebService 开发
- 下一篇: centos akonadi mysql