English 中文(简体)
母体内与分母体内的隔s
原标题:Mouse coordinates relative to Div inside parent div with scrolls
  • 时间:2012-05-16 20:49:41
  •  标签:
  • jquery
  • css

我在父母离婚(超支:汽车)中有两个分歧:两个差异很大,因此,我为父母领取薪金,问题是,当我上下台和下台时(有时甚至负价值),我如何计算 mo的相对价值时,我会为内部离婚获得可变的摩擦坐标。

jQuery(document).ready(function(){
$("#MnDiv").click(function(e){
var clientXRel = e.clientX - this.offsetLeft;
var clientYRel = e.clientY - this.offsetTop;
var clientCoords = "( " + e.clientX + ", " + e.clientY + " )";
var clientCoordsRel = "( " + clientXRel  + ", " + clientYRel  + " )";
$("span:first").text("( e.clientX, e.clientY ) : " + clientCoords);
$("span:last").text("( clientXRel  , clientYRel  ) : " + clientCoordsRel
+      " ( offsetLeft  , offsetTop  ) : " + this.offsetLeft+ ", " this.offsetTop); 
});

So the Question is How to get the right coordinates relative to the inside Div no matter where the scroll is? The complete Example(jsfiddle) Here

预 收

最佳回答

使用j Query活动 varibles .pageX/code>和.pageY和要素被抵销功能.offset().top .offset(left)。

这样一来,它就象样。

var clientXRel = e.pageX- $(this).offset().left;
var clientYRel = e.pageY - $(this).offset().top;

http://jsfiddle.net/PNLU3/3/

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

Drop down background url in Safari Issue

selectBox.selectCSS { background: url(/Images/replacementSelectBackground.png) top left no-repeat height:auto; } I have an issue in Safari only where the image is not rendering on top ...

CSS specific for Safari

How do you target specifically safari in css with styles?

Aligning textarea in a form

Ive used the following css code to align my form elements: form { position:relative; } form input { position:absolute; left:11em; } However, the textarea element is not aligned correctly with the ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

CSS problem with page footer

I have defined my page footer in the css file as: #footer { position: absolute; height: 50px; text-align: center; background: #66CCCC; bottom: 0px; left: 0px; width: 100%; height: ...