Drag and drop : Drag Constrain : Ajax Layer JAVASCRIPT DHTML TUTORIALS


JAVASCRIPT DHTML TUTORIALS » Ajax Layer » Drag Constrain »

 

Drag and drop



<!-- 

Copyright (c2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>script.aculo.us Drag and drop functional test file</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <script src="./scriptaculous-js-1.6.4src/prototype.js" type="text/javascript"></script>
  <script src="./scriptaculous-js-1.6.4src/scriptaculous.js" type="text/javascript"></script>
  <script src="./scriptaculous-js-1.6.4src/unittest.js" type="text/javascript"></script>
  <style type="text/css" media="screen">
    div.box background: green; width:100px; height:100px }
    div.box-container background: yellow; width:200px; height:200px }
  </style>
</head>
<body>
<h1>script.aculo.us Drag and drop functional test file</h1>

<h2>Draggables/Droppables</h2>

<div id="box-normal" class="box">
  Normal box
</div>

<div id="box-grid-numeric" class="box">
  snap: 25
</div>

<div id="box-grid-array" class="box">
  snap: [5,25]
</div>

<div id="box-grid-procedural" class="box">
  snap: procedural (e.g. constrain to box)
</div>

<div class="box-container">
  <div id="box-grid-procedural-gets-draggable" class="box">
    snap: procedural (e.g. constrain to parent element)
  </div>
</div>

<script type="text/javascript" language="javascript" charset="utf-8">

  new Draggable('box-normal',{snap:false,revert:true});
  new Draggable('box-grid-numeric',{snap:25,revert:true});
  new Draggable('box-grid-array',{snap:[5,25],revert:true});
  new Draggable('box-grid-procedural',{
    snap: function(x,y) {
      return[
        x<100 (x > ? x : 100,
        y<50 (y > ? y : 050];
    },
    revert:true
  });
  new Draggable('box-grid-procedural-gets-draggable',{
    snap: function(x,y,draggable) {
      function constrain(n, lower, upper) {
        if (n > upperreturn upper;
        else if (n < lowerreturn lower;
        else return n;
      }
     
      element_dimensions = Element.getDimensions(draggable.element);
      parent_dimensions = Element.getDimensions(draggable.element.parentNode);
      return[
        constrain(x, 0, parent_dimensions.width - element_dimensions.width),
        constrain(y, 0, parent_dimensions.height - element_dimensions.height)];
    },
    revert:true
  });

</script>


</body>
</html>
           
       

Download : Download nav_scriptaculous-js-1.6.4.zip nav_scriptaculous-js-1.6.4.zip


-

Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

JAVASCRIPT DHTML TUTORIALS

 Navioo Ajax Layer
» Drag Constrain