在开发移动端h5时遇到图片加载不出来的问题,分为大图片和小图片(打包base64区分)
大图片加载解决办法:reload预加载
小图片加载解决办法:div标签替换为img标签
特殊情况:
div标签按钮有点击动效,即按下按钮时active替换为另一张图片
原代码:
// html
<div
:src="startBtn"
@click="startGame"
class="game-btn"
@touchstart="" // 解决iOS上active动效不生效问题
><div/>
// css
.game-btn {
position: absolute;
width: 180px;
height: 180px;
margin-top: 280px;
background: url("../../imgs/game-start-btn.png") no-repeat center/contain;
&:active {
background-image: url("../../imgs/game-start-btn-on.png");
}
}
改后:
// html
<img
:src="startBtn"
@click="startGame"
class="game-btn"
@touchstart="startBtnChange('start')"
@touchend="startBtnChange('end')"
/>
// data
startBtn: require("../../imgs/game-start-btn.png"),
btnUrls: {
start: require("../../imgs/game-start-btn-on.png"),
end: require("../../imgs/game-start-btn.png"),
},
// js
startBtnChange(val) {
this.startBtn = this.btnUrls[val];
},
// css
.game-btn {
position: absolute;
width: 180px;
height: 180px;
margin-top: 280px;
}