放大镜功能:
===========
<STYLE type=text/css>#mglass {
LEFT: -2000px; POSITION: absolute; TOP: 50px
}
#thumb {
LEFT: -2000px; POSITION: absolute; TOP: 50px
}
#large {
LEFT: -2000px; POSITION: absolute; TOP: 50px
}
#framegif {
LEFT: -2000px; POSITION: absolute; TOP: 50px
}
.baseline {
FONT-SIZE: 9pt; LEFT: 50px; COLOR: #000000; FONT-FAMILY: Arial; POSITION: absolute; TOP: 260px
}
</STYLE><BODY onload=init()>
<SCRIPT>
var isNav, isIE
var offsetX, offsetY
var selectedObj var enlargefactor=5var largewidth = 455
var largeheight = 523
var largeleft = 300
var largetop = 80var thumbwidth = Math.floor(largewidth/enlargefactor)
var thumbheight = Math.floor(largeheight/enlargefactor)
var thumbleft = 50
var thumbtop = 80var mglasswidth = 32
var mglassheight = 32
var mglassleft = 120
var mglasstop = 110var difleft= largeleft-thumbleft
var diftop= largetop-thumbtopvar clippointsvar cliptop = (thumbheight-mglassheight)*enlargefactor
var clipbottom = cliptop+(mglassheight*enlargefactor)
var clipleft =(thumbwidth-mglasswidth)*enlargefactor
var clipright = clipleft+(mglasswidth*enlargefactor)
if (parseInt(navigator.appVersion) >= 4) {
if (navigator.appName == "Netscape") {
isNav = true
} else {
isIE = true
}
}function setZIndex(obj, zOrder) {
obj.zIndex = zOrder
}function shiftTo(obj, x, y) {
if (isNav) {
obj.moveTo(x,y)
} else {
obj.pixelLeft = x
obj.pixelTop = y
}
cliptop = (y-thumbtop)*enlargefactor
clipbottom = cliptop+(mglassheight*enlargefactor)
clipleft = (x-thumbleft)*enlargefactor
clipright = clipleft+(mglasswidth*enlargefactor)
if (document.all) {
clippoints ="rect("+cliptop+" "+clipright+" "+clipbottom+" "+clipleft+")"
document.all.large.style.posTop=largetop-cliptop
document.all.large.style.posLeft=largeleft-clipleft
document.all.large.style.clip=clippoints
}
if (document.layers) {
document.large.top=largetop-cliptop
document.large.left=largeleft-clipleft
document.large.clip.left = clipleft
document.large.clip.right = clipright
document.large.clip.top = cliptop
document.large.clip.bottom = clipbottom
}
}
<!-- 此特效使用《网页特效精灵》编辑制作-->
<!-- 奥天软件:http://www.aosky.net-->
function setSelectedElem(evt) {
if (isNav) {
var testObj
var clickX = evt.pageX
var clickY = evt.pageY
for (var i = document.layers.length - 1; i >= 0; i--) {
testObj = document.layers[i]
if ((clickX > testObj.left) && 
(clickX < testObj.left + testObj.clip.width) && 
(clickY > testObj.top) && 
(clickY < testObj.top + testObj.clip.height)) {
selectedObj = testObj
setZIndex(selectedObj, 100)
return
}
}
} else {
var imgObj = window.event.srcElement
if (imgObj.parentElement.id.indexOf("mglass") != -1) {
selectedObj = imgObj.parentElement.style
setZIndex(selectedObj,100)
return
}
}
selectedObj = null
return
}function dragIt(evt) {
if (selectedObj) {
if (isNav) {
shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY))
} else {
shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY))
return false
}
}
}function engage(evt) {
setSelectedElem(evt)
if (selectedObj) {
if (isNav) {
offsetX = evt.pageX - selectedObj.left
offsetY = evt.pageY - selectedObj.top
} else {
offsetX = window.event.offsetX
offsetY = window.event.offsetY
}
}
return false
}function release(evt) {
if (selectedObj) {
setZIndex(selectedObj, 0)
selectedObj = null
}
}function setNavEventCapture() {
if (isNav) {
document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
}
}function init() { if (document.layers) {
document.large.left=largeleft
document.large.top=largetop

document.framegif.left=largeleft-3
document.framegif.top=largetop-3

document.thumb.left=thumbleft
document.thumb.top=thumbtop

document.mglass.left=mglassleft
document.mglass.top=mglasstop

document.large.clip.left = 0
document.large.clip.right = 0
document.large.clip.top = 0
document.large.clip.bottom = 0

setNavEventCapture()
}

if (document.all) {
document.all.large.style.posLeft=largeleft
document.all.large.style.posTop=largetop

document.all.framegif.style.posLeft=largeleft-3
document.all.framegif.style.posTop=largetop-3

document.all.thumb.style.posLeft=thumbleft
document.all.thumb.style.posTop=thumbtop

document.all.mglass.style.posLeft=mglassleft
document.all.mglass.style.posTop=mglasstop
document.all.large.style.clip="rect(0 0 0 0)"
}

document.onmousedown = engage
document.onmousemove = dragIt
document.onmouseup = release
}
</SCRIPT><DIV id=thumb><IMG src="beauty.jpg" width=91 
name=thumbpic></DIV>
<DIV id=framegif><IMG height=166 src="glassframe.gif" width=166 
name=framepic></DIV>
<DIV id=large><IMG src="beauty.jpg" width=455  
name=largepic></DIV>
<DIV id=mglass><IMG height=50 src="mglass.gif" width=50 
name=mglasspic></DIV>
</BODY></HTML>

解决方案 »

  1.   

    这个是移动图片的,我想你用得着的。<div style='position:absolute;width:200;height:200;background:red' onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>
    <img src="http://expert.csdn.net/images/csdn.gif" width="4790" height="3580">
    </div>
    <script>
    var Obj
    function MouseDown(obj){
    Obj=obj
    Obj.setCapture()
    Obj.l=event.x-Obj.style.pixelLeft
    Obj.t=event.y-Obj.style.pixelTop
    }
    function MouseMove(){
    if(Obj!=null){
    Obj.style.left = event.x-Obj.l
    Obj.style.top = event.y-Obj.t
    }
    }
    function MouseUp(){
    if(Obj!=null){
    Obj.releaseCapture()
    Obj=null
    }
    }
    </script>
      

  2.   

    TO kingerq(多菜鸟):
      在第一次移动页面图像时,被移动的对象会突然移到左上角,请问如何解决?
    后来观察到,第一次时,obj.style.pixelLeft和obj.style.pixelTop全是0,所以造成问题所在.