• 회원가입
  • 로그인
  • 구글아이디로 로그인

[attribute] HTML - ondragend 속성 - 드래그 종료 시 실행 (= ondragend속성 = 온드래그엔드속성) ※ ondragend이벤트 = 온드래그엔드이벤트

목차
  1. ondragend 예제 - darg 종료 시 실행
  2. ondragend 정의
  3. ondragend 구문

 

ondragend 예제 - darg 종료 시 실행

 

<style>

.box {

  float: left;

  width:200px;

  height:50px;

  padding: 20px;

  margin: 30px;

  text-align:center;

  border: 3px solid gray;

}

</style>


<div class="box" ondragenter="dragenterHZ(event)" ondragleave="dragleaveHZ(event)" ondrop="dropHZ(event)" ondragover="dragoverHZ(event)">

  <p ondragstart="dragstartHZ(event)" ondrag="dragHZ(event)" ondragend="dragendHZ(event)" draggable="true" id="hz">홈짱닷컴 Homzzang.com</p>

</div>


<div class="box" ondragenter="dragenterHZ(event)" ondragleave="dragleaveHZ(event)" ondrop="dropHZ(event)" ondragover="dragoverHZ(event)"></div>


<p style="clear:both;" id="demo"></p>


<script>

function dragstartHZ(event) {

  event.dataTransfer.setData("Text", event.target.id);

  document.getElementById("demo").innerHTML = "p요소 drag 시작";

}


function dragHZ(event) {

  document.getElementById("demo").innerHTML = "p요소 drag 중";

}


function dragendHZ(event) {

  document.getElementById("demo").innerHTML = "p요소 drag 완료";

}   


function dragenterHZ(event) {

  if ( event.target.className == "box" ) {

    event.target.style.borderColor = "red";

    document.getElementById("demo").innerHTML = "드롭박스 진입";

  }

}


function dragoverHZ(event) {

  event.preventDefault(); // 드롭 허용

}    

    

function dragleaveHZ(event) {

  if ( event.target.className == "box" ) {

    event.target.style.borderColor = "";

    document.getElementById("demo").innerHTML = "드롭박스 이탈";

  }

}    


function dropHZ(event) {

  event.preventDefault();

  var data = event.dataTransfer.getData("Text");

  event.target.appendChild(document.getElementById(data));

  document.getElementById("demo").innerHTML = "드롭 완료";

</script>

 

 

ondragend 정의

 

해당요소 드래그가 종료될 때 발생.

 



1.

  • Drag & Drop은 HTML5의 매우 일반적인 기능임.
  • 요소를 드래그 가능하게 만들려면 draggable 전역속성 사용.
  • 링크와 이미지는 기본적으로 드래그 가능. (즉, draggable 속성 불필요.)
  • Drag & Drop 과정의 여러 단계에서 여러 이벤트가 발생함.


2. 드래그요소에서 발생하는 이벤트 :

  • ondragstart 속성 - 사용자가 요소를 드래그하기 시작할 때 발생
  • ondrag 속성 - 요소를 끌 때 발생 (※ 드래그 중  350밀리초마다 실행됨)
  • ondragend 속성 - 사용자가 요소 끌기를 완료하면 실행됩니다.


3. 드롭박스에서 발생하는 이벤트:

  • ondragenter 속성 - 드래그 된 요소가 드롭박스에 들어갈 때 실행.
  • ondragover 속성 - 드래그 된 요소가 드롭박스 위에 있을 때 실행.
  • ondragleave 속성 - 드래그 된 요소가 드롭박스를 벗어날 때 실행.
  • ondrop 속성 - 드래그 된 요소에 드롭박스에 드롭될 때 실행.


4.

IE9 이상 주요 최신 브라우저 모두 지원.

 


ondragend 구문

 

HTML 방식

  • <element ondragend="myScript">

 

JS 방식 (3가지)

  • object.ondragend = ()=>{myScript};
  • object.ondragend = function(){myScript};
  • object.addEventListener("dragend", myScript);



[속성값]

 

myScript

드래그 종료 시, 실행할 JS 코드

  • 주의: 함수명 사용 시, 다른 곳은 전부 소괄호까지 사용해 함수 호출하나 핑크색 myScript 자리는 "함수명만" 사용해 함수 호출.
  • 사용 방식 통일 권장.

 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
attribute HTML - onkeyup 속성 ★ - 키보드키 올라갈 때 실행 (= onkeyup속성 = 온키업속성) ※ …
attribute HTML - onload 속성 ★ - 지정 객체가 로드된 경우 실행 (= onload속성 = 온로드속성) ※…
attribute HTML - onloadeddata 속성 - 미디어 로드되고 준비 완료 시 실행 (= onloadeddata…
attribute HTML - onloadedmetadata 속성 - 미디어 로드되고 준비 완료 시 실행 (= onloaded…
attribute HTML - onloadstart 속성 - 미디어 로드 시작 시 실행 (= onloadstart속성 = 온…
attribute HTML - onmousedown 속성 - 마우스버튼 내려갈 때 실행 (= onmousedown속성 = 온마…
attribute HTML - onmousemove 속성 ★ - 마우스커서가 지정요소 안으로 이동 시 실행 (= onmouse…
attribute HTML - onmouseout 속성 ★ - 마우스커서가 지정요소 밖으로 이동 시 실행 (= onmouseo…
attribute HTML - onmouseover 속성 ★ - 마우스커서가 지정요소 위에 있을 때 실행 (= onmouseo…
attribute HTML - onmouseup 속성 - 마우스버튼 올라갈 때 실행 (= onmouseup속성 = 온마우스업속…
attribute HTML - onmousewheel 속성 - (폐기예고) 마우스휠 움직일 때 실행 (= onmousewhe…
attribute HTML - onoffline 속성 - 브라우저가 오프라인으로 작동할 때 실행 (= onoffline속성 =…
attribute HTML - ononline 속성 - 브라우저가 온라인으로 작동할 때 실행 (= ononline속성 = 온온…
attribute HTML - onpagehide 속성 - 웹페이지가 숨겨질 때 실행 (= onpagehide속성 = 온페이지…
attribute HTML - onpageshow 속성 - 사용자가 웹페이지 탐색 시 실행 (= onpageshow속성 = 온…
attribute HTML - onpaste 속성 - 사용자가 요소에 내용 붙여넣기 시 실행 (= onpaste속성 = 온패스…
attribute HTML - onpause 속성 - (오디오/비디오) 일시정지 시 실행 (= onpause속성 = 온포스속성…
attribute HTML - onplay 속성 - (오디오/비디오) 재생 시 실행 (= onplay속성 = 온플레이속성) ※…
attribute HTML - onplaying 속성 - (오디오/비디오) 재생 중 실행 (= onplaying속성 = 온플레…
attribute HTML - onpopstate 속성 - 브라우저 히스토리 변경 시 실행 (= onpopstate속성 = 온…
13/18
목록
찾아주셔서 감사합니다. Since 2012