每天一個JavaScript執行個體-點擊圖片顯示大圖,javascript大圖

來源:互聯網
上載者:User

每天一個JavaScript執行個體-點擊圖片顯示大圖,javascript大圖

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>每天一個JavaScript執行個體-點擊圖片顯示大圖</title><style>img{padding:5px;width:100px;height:auto;}#outer{width:100%;height:100%;}.overlay{background-color:#000;opacity: .7;filter:alpha(opacity=70);position: fixed;top:0;left:0;width:100%;height:100%;z-index: 10;}.overlayimg{position: absolute;z-index: 11;left:50px;top:30px;width:auto;}</style><script>function expandPhoto(){var overlay = document.createElement("div");overlay.setAttribute("id","overlay");overlay.setAttribute("class","overlay");document.body.appendChild(overlay);var img = document.createElement("img");img.setAttribute("class","overlayimg");img.src = this.getAttribute("src");document.getElementById("overlay").appendChild(img);img.onclick = restore;}function restore(){document.body.removeChild(document.getElementById("overlay"));document.body.removeChild(document.getElementById("img"));}window.onload = function(){var imgs = document.getElementsByTagName("img");imgs[0].focus();for(var i = 0;i<imgs.length;i++){imgs[i].onclick = expandPhoto;imgs[i].onkeydown = expandPhoto;}}</script></head><body><div id = "outer"><p>點擊圖片</p><img src="http://e.hiphotos.baidu.com/image/pic/item/77094b36acaf2edde7684cc38e1001e93901937a.jpg" /><img src="http://e.hiphotos.baidu.com/image/pic/item/77094b36acaf2edde7684cc38e1001e93901937a.jpg" /></div></body></html>


在javascript中編寫代碼使其實現點擊圖片顯示另外一張大圖 點擊大圖關閉該大圖

不用那麼麻煩,改成我寫的:初始化隱藏用CSS,選擇圖片用函數,這樣你可以任意增加圖片

<style type="text/css">
.yincang
</style>
<script type="text/javascript">
function change(){
var name=document.form.Name.value;
var divs=document.getElementsByTagName("div");
var selName=document.getElementById("selName");
for(var i=0;i<divs.length;i++){
divs[i].style.display="none";
}
if(selName.selectedIndex!=0){
divs[selName.selectedIndex-1].style.display="block";
}
}
</script>
<body>
<form action="" method="post" name="form" id="form">
<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr style="font-size:24px; color:#0000FF " align="center"><td>精美人物圖片選擇</td></tr>
<tr style="font-size:12px; color:#FF0099; width:263" align="center" ><td>你要選擇一張圖片喔
<select id="selName" name="Name" onchange="change()">
<option >--選擇人物</option>
<option value="我......">我......</option>
<option value="你......">你......</option>
<option value="她......">她......</option>
<option value="他......">他......</option>
</select></td></tr>
<tr><td>
<div i......餘下全文>>
 
javascript怎實現,點擊一個小圖片,可以把這個圖片放大?

我也正在學習中,這個是我找到的答案 希望對你有協助,
給圖片綁定onmouseover和onmouseout事件,如onmouseover="showdiv(this.src)" onmouseout="hidediv();"滑鼠移到圖片的時候就顯示出一個div,這個div要絕對位置,div裡面是又一個<img>標籤,可以把這個img 的height width都設大一點,<script >function showdiv(src){document.getElementById("div").style.display="block";//給div定位document.getElementById("img").src=src;}</script> <div id="div" style="display:none;"><!--寬高自己設一下--> <img id="img" ><!--寬高自己設一下--> </div>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.