jquery Sets the top value (instance code) of an element relative to another element _jquery

Source: Internet
Author: User

<div id= "Span1" >sfdsfsddfsdf</div>
<span id= "span2" style= "position:relative" >

<input id= "Input" type= "text" ></input>
<input id= "button" type= "button" ></input>

</span>

Set the button below the input

$ ("#button"). CSS ("{TOP": $ ("#input"). Offset (). top-$ ("#span2"). Offset (). top+$ ("#input"). Height,position: " Absolute "});

So the public opinion input in which position button is in the input of the bottom, the same can be applied to the calendar widget in the input text box below

1, in jquery () offset (). Top is relative to the body, and when you set the top value, you find the element that has the closest relative value to the element

In JS, you can write this:

Copy Code code as follows:

Get the absolute position of an HTML control
Calendar.prototype.getAbsPoint = function (e) {
var x = E.offsetleft;
var y = e.offsettop;
while (E = e.offsetparent) {
x + + E.offsetleft;
Y + + e.offsettop;
}
return {"X": X, "Y": y};
}

var xy = this.getabspoint (Popcontrol);
This.panel.style.left = xy.x + "px";

This.panel.style.top = (xy.y + dateobj.offsetheight) + "px";


As shown in the figure:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.