實現點擊圖片彈出選擇文件窗口

不少時候,須要實現這樣的效果:用戶已經上傳頭像,點擊頭像以後直接彈出圖片選擇窗口。html

能夠經過以下代碼實現:url

<div style="width:.6rem;height:.6rem;background: url(img/protrait.jpg);background-size:.6rem .6rem;">
  <input type="file" id="file" style="filter:alpha(opacity=0);opacity:0;width:100%;height:100%;" />
</div>

原理就是:將input覆蓋住要點擊的圖片或者超鏈或者其它div,而後將input設置成徹底透明,這樣點擊圖片時其實點擊的是input。code

相關文章
相關標籤/搜索