請與下面的代碼嘗試
你的HTML
<div>
<img src="@Model.ComponentData.imagePath" onclick="OpenBookRead(@Model.ComponentData.Id)" class="actualImage"/>
<img src="@Model.ComponentData.imagePath" onclick="OpenBookRead(@Model.ComponentData.Id)" class="defaultImage"/>
</div>
請CSS屬性 「不透明度」 添加到你的風格
<style>
.actualImage {
opacity: 0;
position:absolute;
height:150px;
width:100px;
}
.actualImage.show-actual-image {
opacity: 1;
}
.defaultImage {
height:150px;
width:100px;
}
</style>
添加按照腳本t Ø根據您的實際圖像可用性
<script>
$(".actualImage")
.on('load', function() { $(this).addClass("show-actual-image");})
.on('error', function() { $(this).removeClass("show-actual- image");});
</script>
我認爲這將幫助您管理透明度....
您可以使用下面的代碼也... 它工作正常
HTML
<div class="Landscape" style="position: relative;">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQ_Tm3R3OxcWhSFwaLNhG0iQUq2RqT3pnTEgSN3u1YDc44lMRWlFA" class="actualImage" />
<img src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcTCb5jUiDyPAQM2DmOn9V37FJwHUkaeCTTIsorbI-tKegIDHb-qZQ" class="defaultImage" />
CSS
.landscape {
position: relative;
height: 130px;
width: 198px;
}
.actualImage,
.defaultImage{
position: absolute;
left: 0;
top: 0;
width: 100%;
z-index: 1;
}
.actualImage {
opacity: 0;
}
.actualImage.show-actual-image {
opacity: 1;
z-index: 999;
}
的Javascript
var imgElement = document.getElementsByClassName("actualImage")[0];
if (imgElement.complete) {
alert("hi");
imgElement.className += " show-actual-image";
}
我已經添加了1個答案。請檢查。 –
請檢查更新後的答案 –