>  기사  >  웹 프론트엔드  >  자바스크립트 이미지 미리보기 기능 구현코드 공유

자바스크립트 이미지 미리보기 기능 구현코드 공유

黄舟
黄舟원래의
2017-03-25 14:15:011399검색

이 글에서는 주로 javascript에서 구현한 이미지 미리보기 기능을 예제와 결합하여 소개합니다. form 자바스크립트 관련 기능의 구현 능력과 메모를 분석했습니다. 도움이 필요한 친구는

이 글에서 자바스크립트로 구현한 이미지 미리보기 기능을 설명하고 참고할 수 있도록 공유합니다. 자세한 내용은 다음과 같습니다.

1. 다음 코드를

<script>
/*
Thumbnail image viewer-
?Dynamic Drive (www.dynamicdrive.com)
For full source code, usage terms, and 100&#39;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=&#39;<img src="&#39;+which+&#39;">&#39;
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(&#39;<a href="#" rel="external nofollow" onMouseover="drag_dropns(showimage)"><img src="&#39;+which+&#39;" border=0></a>&#39;)
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. 다음 코드를 사용하여

을 추가합니다. :

<p id="showimage" style="position:absolute;visibility:hidden"></p>

3. 이미지가 연결된 곳에

를 작성합니다. 코드는 다음과 같습니다.

<a href="photo1.jpg" rel="external nofollow" onClick="return enlarge(&#39;photo1.jpg&#39;,event)">
<img src="thumbnail.gif" border="0"></a>

이미지 경로를 변경하세요

위 내용은 자바스크립트 이미지 미리보기 기능 구현코드 공유의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.