JavaScript に慣れていないため、検索してもうまくいきませんでした。ページの読み込み時に div の背景画像として表示されるように、javascript を使用して、既に html の本体にある画像 (css の可視性が非表示) を読み込むことは可能ですか?
1 に答える
2
はい。
好きなだけ
<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>
ここでサンプルフィドルを見ることができます
于 2013-05-24T07:56:59.957 に答える