I would like to capture the position of a draggable element after it''s
being dragged, but I am running into problem using several options, such
as "change", "revert" and "onEnd". My callback
handler would only fire
when the page loads, and not when the element is dragged. How can I make
this happen?
<html>
<head>
<script src="/scriptaculous-js-1.5.1/lib/prototype.js"
type="text/javascript"></script>
<script src="/scriptaculous-js-1.5.1/src/scriptaculous.js"
type="text/javascript"></script>
</head>
<body>
<table id="a">
<tr>
<td>draggable</td>
</tr>
</table>
<script type ="text/javascript" language="javascript">
new Draggable(''a'',{onEnd:alert(this)});
</script>
</form>
</body>
</html>
--
Posted via http://www.ruby-forum.com/.
Douglas Livingstone
2006-Jan-14 15:44 UTC
[Rails] Capturing the position of a draggable element
2006/1/13, jeannie lu <jeannielu@hotmail.com>:> <script type ="text/javascript" language="javascript"> > new Draggable(''a'',{onEnd:alert(this)}); > </script>What that does, is assign the return value of "alert(this)" (probably false or something) to options.onEnd. A simple way to do what you want would be: <script type ="text/javascript" language="javascript"> new Draggable(''a'',{endeffect:function(){alert(this)}}); </script> but a more powerful solution would be to create your own object to handle the dragging, which would look something like this: var MyDraggable = Class.create(); MyDraggable.prototype = { initialize: function (element, options) { // script.aculo.us drag and drop new Draggable(element, options); Draggables.addObserver(this); }, onEnd: function () { // your code here } } hth, Douglas