AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > JavaScript

javascript实现的图片预览功能

51自学网 http://www.wanshiok.com
javascript,图片预览

本文实例讲述了javascript实现的图片预览功能。分享给大家供大家参考,具体如下:

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.clientXshowimage.style.top=document.body.scrollTop+event.clientYshowimage.innerHTML='<img src="'+which+'">'showimage.style.visibility="visible"}elseshowimage.style.visibility="hidden"return false}//Render image code for NS 4else 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.xdocument.showimage.top=e.ydocument.showimage.visibility="show"}elsedocument.showimage.visibility="hide"return false}//if NOT IE 4+ or NS 4, simply display image in full browser windowelsereturn true}</script><script language="Javascript1.2">//By Dynamicdrive.com//drag drop function for NS 4/////////////////////////////////////var nsxvar nsyvar nstempfunction drag_dropns(name){temp=eval(name)temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)temp.onmousedown=gonstemp.onmousemove=dragnstemp.onmouseup=stopns}function gons(e){temp.captureEvents(Event.MOUSEMOVE)nsx=e.xnsy=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=falsefunction drag_dropie(){if (dragapproved==true){document.all.showimage.style.pixelLeft=tempx+event.clientX-iexdocument.all.showimage.style.pixelTop=tempy+event.clientY-ieyreturn false}}function initializedragie(){if (event.srcElement.parentElement.id=="showimage"){iex=event.clientXiey=event.clientYtempx=showimage.style.pixelLefttempy=showimage.style.pixelTopdragapproved=truedocument.onmousemove=drag_dropie}}if (document.all){document.onmousedown=initializedragiedocument.onmouseup=new Function("dragapproved=false")}</script>

2.在<body>中加入

复制代码 代码如下:
<div id="showimage" style="position:absolute;visibility:hidden"></div>

3.在连接图片的地方这样写

复制代码 代码如下:
<a href="photo1.jpg" rel="external nofollow" onClick="return enlarge('photo1.jpg',event)"><img src="thumbnail.gif" border="0"></a>

记得更改图片路径

更多关于Javascript相关内容感兴趣的读者可查看本站专题:《Javascript图片操作技巧大全》、《Javascript切换特效与技巧总结》、《Javascript图形绘制技巧总结》、《Javascript查找算法技巧总结》、《Javascript错误与调试技巧总结》、《Javascript数据结构与算法技巧总结》、《Javascript遍历算法与技巧总结》及《Javascript数学运算用法总结

希望本文所述对大家Javascript程序设计有所帮助。


javascript,图片预览  
上一篇:JS操作xml对象转换为Json对象示例  下一篇:JS控件bootstrap suggest plugin使用方法详解