'addEventListener'에 해당되는 글 3건

  1. 2017.09.07 클릭 드레그 하면 따라다니는 div
  2. 2017.09.06 붙여넣기 이벤트 처리 ctrl+v
  3. 2017.09.06 div 에다가 클릭 이벤트 걸기

 

 




<html>
<head>
</head>


<script  language="javascript"  >


 /*Click and drag to follow the div */


 var div_a1;


 function init(){
   div_a1 = document.getElementById('a1');
   var groundDiv = document.getElementById('groundDiv');
   groundDiv.addEventListener('mousedown', mouseDown);
   groundDiv.addEventListener('mousemove', mouseMove);
   groundDiv.addEventListener('mouseup', mouseUp);
 }


 var isClick = false; 
 function mouseDown(e){
   isClick = true;
 }
 
 function mouseMove(e){
   if( isClick == true ){
     div_a1.style.left = e.offsetX - 20 + 'px';
     div_a1.style.top = e.offsetY - 20 + 'px';     
   }
 }
 
 function mouseUp(e){
   isClick = false;
 }


</script>
    <body  onload="init();" >
        <div id="groundDiv"  style="position:relative; width:99%; height:99%; border:0x solid black;"></div>
        <div id='a1'  style="position:absolute; width:3px; height:3px; border:2px solid black;top:2px;left:3px  " ></div>
    </body>
</html>




 

 

Posted by 혜화초보
,

/*

paste event

*/



<html>

<head>


<style type="text/css">

 <!--

  #base1 {

  background-color: #F3F2F6;

  width: 10px;

  height: 10px;

  position:absolute;

  top: 200px;

  }

 //-->

 </style>


</head>


<script  language="javascript"  >

 /*

 */

 var ppp = 0;


 function init(){

   var groundDiv = document.getElementById('c2');

   groundDiv.addEventListener("paste", handler , false);   // all browsers and IE9+

   //groundDiv.attachEvent ("onpaste", handler);  // IE<9

 }

 

 function handler(){

    setTimeout(function(){

       var groundDiv = document.getElementById('c2').value;

       console.log('value:: ' + groundDiv );

    }, 0); //or 4

 }


</script>

    <body  onload="init();"   >

        <div id='base1' >

          <input type='text'  size='20'  name='c1' id='c2' >

        </div>

    </body>

</html>

'[.js] 이벤트' 카테고리의 다른 글

onClick onFocus eventListener  (0) 2017.09.08
div 에다가 클릭 이벤트 걸기  (0) 2017.09.06
Posted by 혜화초보
,


 




/*

설명 :  화면을 열고 click 클릭하면 이벤트가 등록되고

        a1 의 div 를 클릭하면 hello 콘솔창에 찍힘.


재밌는건 click 여러번 클릭하면 리스너도 여러번 등록되서

hello도 여러번 출력됨.

*/


<html>

<head>

</head>

<script  language="javascript"  >


function exe(){


  var div1 = document.getElementById("a1");

  div1.addEventListener('click', function (event) {

    console.log(' hello ~ ');   

  });

}




</script>

    <body  >

        <div  id='a1'  style="  height:80px ; padding-top:200px ;

            background-color: lightblue;

            padding-left:200px "  >

          <a href="javascript:exe();"  >  click  </a>        

        </div>

        

 

    </body>

</html>










'[.js] 이벤트' 카테고리의 다른 글

onClick onFocus eventListener  (0) 2017.09.08
붙여넣기 이벤트 처리 ctrl+v  (0) 2017.09.06
Posted by 혜화초보
,