Hi list, how can I set the top and left CSS properties for draggable divs? When I modify the properties directly, the DIV jumps to its old position when I start to drag it. Thanks in advance! Martin _________________________________________________________________________ Mit der Gruppen-SMS von WEB.DE FreeMail k?nnen Sie eine SMS an alle Freunde gleichzeitig schicken: http://freemail.web.de/features/?mc=021179
Martin Bialasinski
2005-Aug-15 17:00 UTC
[Rails-spinoffs] setting position for draggables?
On 15/08/05, Martin Scheffler <wooyay@web.de> wrote:> how can I set the top and left CSS properties for draggable divs? When I modify the properties directly, the DIV jumps to its old position when I start to drag it.This is because the Draggable remembers the position it had on endDrag. I suggest, you add a moveBy(x,y) method to Draggable, that moves the Element by updating this.originalLeft, this.originalTop is addition to style.top, and style.left For the sake off completeness, you could also add a moveTo(x,y) method with moveTo(123, null) -> leave the old y value moveTo(null, 123) -> leave the old x value Then send in a diff :-) Bye, Martin
I dont think adding a moveby-function is a good idea. I instead did a quick hack of the dragdrop.js, and now I can use the moveBy-effect, which is sweet! I changed the startDrag function so it gets its start position from the style. I guess this is ugly and can break some other things, but it seems to work for me. Maybe someone with more insight into this library can have a look at it. startDrag: function(event) { if(Event.isLeftClick(event)) { this.active = true; var style = this.element.style; //---------- this.originalTop=parseInt(this.element.style.top); this.originalLeft=parseInt(this.element.style.left); //---- this.originalY = this.element.offsetTop - this.currentTop() - this.originalTop; this.originalX = this.element.offsetLeft - this.currentLeft() - this.originalLeft; this.offsetY = event.clientY - this.originalY - this.originalTop; this.offsetX = event.clientX - this.originalX - this.originalLeft; Event.stop(event); } }, _________________________________________________________________________ Mit der Gruppen-SMS von WEB.DE FreeMail k?nnen Sie eine SMS an alle Freunde gleichzeitig schicken: http://freemail.web.de/features/?mc=021179
The error does not happen when I use 1.5_pre2, so please ignore my previous post. But another thing: With the moveBy effect, the afterFinish callback seems to be triggered at the start of the effect. What''s up with that? _________________________________________________________________________ Mit der Gruppen-SMS von WEB.DE FreeMail k?nnen Sie eine SMS an alle Freunde gleichzeitig schicken: http://freemail.web.de/features/?mc=021179
Martin Bialasinski
2005-Aug-16 15:42 UTC
[Rails-spinoffs] setting position for draggables?
On 16/08/05, Martin Scheffler <wooyay@web.de> wrote:> But another thing: With the moveBy effect, the afterFinish callback seems to be triggered at the start of the effect.Place an alert() into the callback to see if it really is the case. No need to guess. Bye, Martin
new to this list, hi all. Relying on the style property is not so good as that''s only going to get values explicity set via script, or in the style attribute. I use the following helper function to get the calculated style (when properties set via classes etc have been applied) document.getComputedStyleOf = function (el) { return (typeof el.currentStyle == ''undefined'') ? document.defaultView.getComputedStyle(el, "") : el.currentStyle; } ..so you''d say var style = document.getComputedStyleOf(el); .. and get the left, top property like so: top = style.top, left = style.left etc. Or, for one time property access: document.getComputedStyleOf(el).left this works for most properties, and on most browsers Sam -i-am
Such a method is already in there (Element.getStyle). Note that browsers tend to not "agree" on some of the CSS properties when called this way (but mostly it works, yes). Some functions already use this internally, more will follow. Thomas Am 17.08.2005 um 01:24 schrieb Sam Foster:> new to this list, hi all. > > Relying on the style property is not so good as that''s only going > to get values explicity set via script, or in the style attribute. > I use the following helper function to get the calculated style > (when properties set via classes etc have been applied) > > document.getComputedStyleOf = function (el) { > return (typeof el.currentStyle == ''undefined'') ? > document.defaultView.getComputedStyle(el, "") : el.currentStyle; > } > ..so you''d say > var style = document.getComputedStyleOf(el); > .. and get the left, top property like so: > top = style.top, > left = style.left > etc. > > Or, for one time property access: > document.getComputedStyleOf(el).left > > this works for most properties, and on most browsers > > Sam > -i-am > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > >