マウスの座標を取得するには、e.pageYとe.pageXを使用します。クラスやIDはどうですか?それは次のようになります:要素の座標の取得
$(this).pageY;
またはそれに類するものはありますか?それは可能ですか?ありがとう。
マウスの座標を取得するには、e.pageYとe.pageXを使用します。クラスやIDはどうですか?それは次のようになります:要素の座標の取得
$(this).pageY;
またはそれに類するものはありますか?それは可能ですか?ありがとう。
offset()
メソッドは、要素の位置(左上)を返します。
var offset = $("selector").offset();
offset.top // Top position, relative to the top of the page
offset.left // Left position, relative to the left of the page
使用がここ
$(".divItem").click(function(){
alert("Left is : "+$(this).offset().left)
});
オフセットはサンプルです:http://jsfiddle.net/ZBeWq/4/
あなたがコンテンツを表すページ全体、つまり文書にいくつかの要素の相対座標を取得するにはワンならば、あなたはoffset()
メソッドを使用することができます。そうでない場合、親要素との相対座標を取得する場合は、position()
メソッドを使用できます。これらの関数は両方とも要素の左上と右上に戻ります。
var absolute_coordinates = $('#mydiv').offset(); // top and left with respect to document
var relative_coordinates = $('#mydiv').position(); //top and left with respect to parent
alert('#mydiv is ' + relative_coordinates.top
+ 'px below from parent and absolute_coordinates.top +
'px below from document');