* Question
$("#para").offset ({left: 50, top: 50});
Give the position left: 50, top: 50
here.
str += "left" is " + paraPosition.left + "pixel";
str + = "top is " + paraPosition.top + "pixel. ";
If you try to output the position value of #para
to parPosition.left
, paraPosition.top
instead of the position value, undefined
is output! I wonder if I can correct this error Crying.
jQuery is specialized in chaining.
Handing args over to $.offset(args...)
returns the previously selected jQuery object.
To receive the top/left as desired, you must call $.offset()
without args.
So if you want to end it in one line,
var paraPosition = $("#para").offset({left : 50 , top : 50}).offset();
If you untie it,
var $para = $("#para");
$para.offset({left : 50 , top : 50});
var paraPosition = $para.offset();
© 2024 OneMinuteCode. All rights reserved.