Understanding about CSS position and scroll events

Source: Internet
Author: User

When I was developing a color picker yesterday, I wanted to locate the ecliper in a pop-up box. So I used the position: absolute attribute. Obtains the position of the clicked element. The method for obtaining its position is to use $ (this). offset (). Left, $ (this). offset (). Top. Because absoulte is located relative to the page. So when I scroll the scroll bar in the pop-up box, it will not scroll. At that time, the solution I came up with was to use a method to obtain whether scroll is scroll up or down.

You can use $ ("Div"). Scroll (). Obtain the scrolltop value and compare it with the value of the previous scroll to determine whether to scroll up or down.

However, I later thought of a more convenient solution, that is, not to use absolute for locating. Insert the element directly to the bottom layer, and use margin-left and margin-Right to locate the element. I personally think this is the best way.

Related Article

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.