[英]JavaScript Background Image Change on page load on Impresspages
[英]Using javascript to load a css hidden image as a background image on page loading
Noob在javascript並且沒有運氣搜索。 是否可以使用javascript加載已經在html(隱藏css可見性)主體中的圖像,以便在頁面加載時作為div中的背景圖像可見?
是。
只是喜歡
<script type="text/javascript">
window.onload = function() {
// get the image url from the src attribute of image
imgurl = document.getElementById("yourImgID").src;
// set it as background to the div you want
document.getElementById("yourDivID").style.background = "url("+imgurl+") no-repeat";
}
</script>
你可以在這里看到一個樣本小提琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.