jeudi 16 juin 2016

with out using jquary ui how i get a draggable div position

i have a time scale div inside draghere div i want drop this timescale dive anywhere in the drag here div.and also i want to know the position .is there any suggestion with out using jquary ui ?

    function funct(e) {

            var id = e.id;
            mouseXY(id);
          
        }

        function mouseXY(id) {

            //alert(id);
            
            var x = event.pageX,
              y = event.pageY
            $('#' + id).css({
                top: y, 
                left: x 
            });
        }                       
<html>
  <head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  
    <style>
      .timescalebase {
    margin-top: 13px;
    height: 7px;
    position: relative;
    width:20%;
  height:5px;
        background-color:green;
    }
      </style>
    </head>
  <body>
<div id draghere style="width:100%;margin-top:25px;background-color:red">
                <div id="timebase1"draggable="true"class="timescalebase activelevel1" ondrag=funct(this)>
                    
                </div>
  </body>
    </html>

how i get the left value of the timebase1 div after drop.if i add this value in "left:x+..". here i thing i will get the answer .how i get this value ?

Aucun commentaire:

Enregistrer un commentaire