javascript實現(xiàn)的圖片預覽功能
本文實例講述了javascript實現(xiàn)的圖片預覽功能。分享給大家供大家參考,具體如下:
1.將下面的代碼復制到<head>內
<script> /* Thumbnail image viewer- ?Dynamic Drive (www.dynamicdrive.com) For full source code, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com */ function enlarge(which,e){ //Render image code for IE 4+ if (document.all){ if (showimage.style.visibility=="hidden"){ showimage.style.left=document.body.scrollLeft+event.clientX showimage.style.top=document.body.scrollTop+event.clientY showimage.innerHTML='<img src="'+which+'">' showimage.style.visibility="visible" } else showimage.style.visibility="hidden" return false } //Render image code for NS 4 else if (document.layers){ if (document.showimage.visibility=="hide"){ document.showimage.document.write('<a href="#" rel="external nofollow" onMouseover="drag_dropns(showimage)"><img src="'+which+'" border=0></a>') document.showimage.document.close() document.showimage.left=e.x document.showimage.top=e.y document.showimage.visibility="show" } else document.showimage.visibility="hide" return false } //if NOT IE 4+ or NS 4, simply display image in full browser window else return true } </script> <script language="JavaScript1.2"> //By Dynamicdrive.com //drag drop function for NS 4//// ///////////////////////////////// var nsx var nsy var nstemp function drag_dropns(name){ temp=eval(name) temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP) temp.onmousedown=gons temp.onmousemove=dragns temp.onmouseup=stopns } function gons(e){ temp.captureEvents(Event.MOUSEMOVE) nsx=e.x nsy=e.y } function dragns(e){ temp.moveBy(e.x-nsx,e.y-nsy) return false } function stopns(){ temp.releaseEvents(Event.MOUSEMOVE) } //drag drop function for IE 4+//// ///////////////////////////////// var dragapproved=false function drag_dropie(){ if (dragapproved==true){ document.all.showimage.style.pixelLeft=tempx+event.clientX-iex document.all.showimage.style.pixelTop=tempy+event.clientY-iey return false } } function initializedragie(){ if (event.srcElement.parentElement.id=="showimage"){ iex=event.clientX iey=event.clientY tempx=showimage.style.pixelLeft tempy=showimage.style.pixelTop dragapproved=true document.onmousemove=drag_dropie } } if (document.all){ document.onmousedown=initializedragie document.onmouseup=new Function("dragapproved=false") } </script>
2.在<body>中加入
3.在連接圖片的地方這樣寫
記得更改圖片路徑
更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript圖片操作技巧大全》、《JavaScript切換特效與技巧總結》、《JavaScript圖形繪制技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript錯誤與調試技巧總結》、《JavaScript數(shù)據(jù)結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數(shù)學運算用法總結》
希望本文所述對大家JavaScript程序設計有所幫助。
- JS+HTML5實現(xiàn)上傳圖片預覽效果完整實例【測試可用】
- javascript圖片預覽和上傳(兼容IE)
- 基于JavaScript實現(xiàn)本地圖片預覽
- 多種方式實現(xiàn)js圖片預覽
- JS實現(xiàn)的圖片預覽插件與用法示例【不上傳圖片】
- 微信js-sdk預覽圖片接口及從拍照或手機相冊中選圖接口用法示例
- JS驗證圖片格式和大小并預覽的簡單實例
- js實現(xiàn)上傳圖片預覽的方法
- JS預覽圖像將本地圖片顯示到瀏覽器上
- js實現(xiàn)上傳圖片之上傳前預覽圖片
- Javascript圖片上傳前的本地預覽實例
- JS實現(xiàn)獲取圖片大小和預覽的方法完整實例【兼容IE和其它瀏覽器】
相關文章
js鍵盤事件keydown事件、防止重復觸發(fā)以及組合鍵的配合使用
這篇文章主要給大家介紹了關于js鍵盤事件keydown事件、防止重復觸發(fā)以及組合鍵配合使用的相關資料,文中通過代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2024-04-04頁面中body onload 和 window.onload 沖突的問題的解決
關于頁面中body onload 和 window.onload 沖突的問題的解決2009-07-07微信小程序開發(fā)之實現(xiàn)食堂點餐系統(tǒng)
這篇文章主要為大家詳細介紹了如何通過微信小程序開發(fā)一個簡單的食堂點餐系統(tǒng),文中的示例代碼講解詳細,感興趣的小伙伴可以和小編一起學習一下2023-01-01