Put the current value of the style attribute in a variable

I have the following dynamic code. I want to put the position values ​​of "left" and "top" in variables. These values ​​change when I drag them around the screen. What I would like to do is save the last values ​​so that when it is destroyed, I can reuse the values ​​to put them in the same place the next time.

<div onmouseover="setTimer();" class="soft_add_wrapper ui-draggable" style="left: 630.5px; top: 182px;">

I have a selector, I think, but then I'm a little fussy

var xyz = $(".soft_add_wrapper ui-draggable").attr xxxxxxxxxxxxxxx
+3
source share
2 answers

You can get the values ​​using .css()as follows:

var left = $(".soft_add_wrapper.ui-draggable").css('left');
var top = $(".soft_add_wrapper.ui-draggable").css('top');

, .offset(), , .position().

, .soft_add_wrapper.ui-draggable, , .

+2

var offset = $(".soft_add_wrapper.ui-draggable").offset();

, :

alert(offset.left);
alert(offset.top);
+2

Source: https://habr.com/ru/post/1756482/


All Articles