회원등록 비번분실

작성자 JAVA
작성일 2002-02-18 (월) 17:40
Link#2 picdrag.html (Down:51)
ㆍ추천: 0  ㆍ조회: 3446      
IP:
마우스로 그림 움직이기
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>- 드래그할 수 있는 이미지</title>
<meta name="generator" content="Namo WebEditor v4.0">
<style>
<!--
body, table, tr, td{
font-family: 굴림, 돋움, verdana;
}
a:link, a:active, a:visited { text-decoration: none; }
a:hover { text-decoration: underline; }
-->
</style>

<style type="text/css">
#plane1 {position:absolute; left:320; top:100; width:121; z-index:0}
#plane2 {position:absolute; left:380; top:165; width:118; z-index:0}
</style>
<SCRIPT LANGUAGE="JavaScript">
var isNav, isIE
if (parseInt(navigator.appVersion) >= 4) {
if (navigator.appName == "Netscape") {
 isNav = true
} else {
 isIE = true
}
}

// ***Begin CSS custom API Functions***
// Set zIndex property
function setZIndex(obj, zOrder) {
obj.zIndex = zOrder
}
// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
if (isNav) {
 obj.moveTo(x,y)
} else {
 obj.pixelLeft = x
 obj.pixelTop = y
}
}
// ***End API Functions***

// Global holds reference to selected element
var selectedObj
// Globals hold location of click relative to element
var offsetX, offsetY

// Find out which element has been clicked on
function setSelectedElem(evt) {
if (isNav) {
 // declare local var for use in upcoming loop
 var testObj
 // make copies of event coords for use in upcoming loop
 var clickX = evt.pageX
 var clickY = evt.pageY
 // loop through all layers (starting with frontmost layer)
 // to find if the event coordinates are in the layer
 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)) {
    // if so, then set the global to the layer, bring it
    // forward, and get outa here
    selectedObj = testObj
    setZIndex(selectedObj, 100)
    return
  }
 }
} else {
 // use IE event model to get the targeted element
 var imgObj = window.event.srcElement
 // make sure it's one of our planes
 if (imgObj.parentElement.id.indexOf("plane") != -1) {
  // then set the global to the style property of the element,
  // bring it forward, and say adios
  selectedObj = imgObj.parentElement.style
  setZIndex(selectedObj,100)
  return
 }
}
// the user probably clicked on the background
selectedObj = null
return
}
// Drag an element
function dragIt(evt) {
// operate only if a plane is selected
if (selectedObj) {
 if (isNav) {
  shiftTo(selectedObj, (evt.pageX - offsetX), (evt.pageY - offsetY))
 } else {
  shiftTo(selectedObj, (window.event.clientX - offsetX), (window.event.clientY - offsetY))
  // prevent further system response to dragging in IE
  return false
 }
}
}
// Set globals to connect with selected element
function engage(evt) {
setSelectedElem(evt)
if (selectedObj) {
 // set globals that remember where the click is in relation to the
 // top left corner of the element so we can keep the element-to-cursor
 // relationship constant throughout the drag
 if (isNav) {
  offsetX = evt.pageX - selectedObj.left
  offsetY = evt.pageY - selectedObj.top
 } else {
  offsetX = window.event.offsetX
  offsetY = window.event.offsetY
 }
}
// block mouseDown event from forcing Mac to display
// contextual menu.
return false
}
// Restore elements and globals to initial values
function release(evt) {
if (selectedObj) {
 setZIndex(selectedObj, 0)
 selectedObj = null
}
}
// Turn on event capture for Navigator
function setNavEventCapture() {
if (isNav) {
 document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
}
}
// Assign event handlers used by both Navigator and IE (called by onLoad)
function init() {
if (isNav) {
 setNavEventCapture()
}
// assign functions to each of the events (works for both Navigator and IE)
document.onmousedown = engage
document.onmousemove = dragIt
document.onmouseup = release
}
</SCRIPT></head>

<body text="black" link="blue" vlink="purple" alink="red" onload="init();">
<p><span style="font-size:9pt;">마우스로 그림을 움직일 수 있습니다.<br>
나모 같은 툴로 수정하시면 안됩니다.</span></p>
<DIV ID=plane1><img src="http://kangjaeg.x-y.net/banner/shopban.gif" border="0" alt="비행기를 마우스로 움직일 수 있읍니다" name="planePic1"></div>
</body>
<span style="font-size:9pt;">DIV ID의 plane 는 맨 위의 STYLE SHEET의 이름과 같아야 합니다.</span>
</body>
</html>


  0
3500