為了紀錄下,以後可能用到,有需要的道友也可以用用。
不BB,上效果圖先
以上就是效果圖。 右上角的圖片可自己換圖片,圖片素材我就不放上來了,我就上個代碼,挺簡單的css和js,初學者應該也看得明白
</pre><pre name=code class=html><!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd><html xmlns=http://www.w3.org/1999/xhtml><head><meta http-equiv=Content-Type content=text/html; charset=utf-8 /><title>無標題文檔</title><style type=text/css>.divX{ z-index:200; -moz-border-radius:20px; -webkit-border-radius:20px; line-height:10px; text-align:center; font-weight:bold; cursor:pointer; font-size:10px;display: none;}</style></head> <body><form id=form style=margin-top:20px;> <div id=img_div_1> <input type=file id=file_input οnchange=addFile(this); style=display:none /> <div style=position: relative;> <img id=file_img src=add_img.png width=75 οnclick=file_input.click(); height=65 /> </div> <div class=divX id=img_zindex_div_1 οnclick=del()> <img src=no.png width=16 height=16 /> </div> </div> </form></body><script src=jquery-1.7.2.js type=text/javascript></script><script type=text/javascript>function addFile(ths) {var objUrl = getObjectURL(ths.files[0]);var left = $('#file_img').position().left;var top = $('#file_img').position().top;$('#img_zindex_div_1').css({position: absolute, left: left + 75, top: top + 10, display: block });$('#file_img').attr(src, objUrl);}function del() {alert(刪除);}function getObjectURL(file) {var url = null ; if (window.createObjectURL!=undefined) { // basicurl = window.createObjectURL(file) ;} else if (window.URL!=undefined) { // mozilla(firefox)url = window.URL.createObjectURL(file) ;} else if (window.webkitURL!=undefined) { // webkit or chromeurl = window.webkitURL.createObjectURL(file) ;}return url ;}</script></html>搞定。收工了。複製代碼,替換下圖片素材就直接能用了
下班。走人
------------------------------------------------------------------------------------------- 華麗分割---------------------------------------------------------------------------------------------------------
補充。由於拿left都是0
換種方式獲取
var objUrl = getObjectURL(ths.files[0]);var left = $('#file_img').offset().left;var top = $('#file_img').offset().top;// left為默認圖的最左側距離, 添加後的圖片可根據默認圖的寬度- 刪除層圖片的寬度(即:當前我默認圖的寬度為75,刪除層的圖片寬度為16, left = 75 - 16, 位置就能到圖片的最右側了! top也是同樣道理)$('#img_zindex_div_1').css({position: absolute, left: left + 59, top: top - 5, display: block });總結到此這篇關於html+css 實現圖片右上角加刪除叉、圖片刪除按鈕的文章就介紹到這了,更多相關html圖片右上角加上刪除內容請搜索武林網以前的文章或繼續瀏覽下面的相關文章,希望大家以後多多支持武林網!