Home > Article > Web Front-end > How to use getBoundingClientRect() to implement scrolling and fixation of div containers
This time I will show you how to use getBoundingClientRect() to achieve scrolling and fixing of div containers, and how to use getBoundingClientRect() to achieve scrolling and fixing of div containers. What are the precautions? What are the practical cases? Let’s take a look. take a look.
The method of ele.getBoundingClientRect() is to obtain the position of an element in the entire view window.
The values that can be returned include width, height, top, left, x ,y,right,bottom
Scene
When one of your divs is in the middle of viewport
The effect you want is that when the page scrolls to this div, this div is fixed at the top of the page, Othersscrolling remains unchanged
Idea
Achieved The idea can be to use this method to get the top value of this div
This top value is the top value of this div to the viewport
Listen to the scrolling of the pageEvent Then when this When the top value
to achieve such an effect
I believe you have mastered the method after reading these cases , for more exciting content, please pay attention to other related articles on the php Chinese website!
Related reading:
How to add it in html flash video format (flv, swf) files
How to set input to read-only effect through disabled and readonly
The above is the detailed content of How to use getBoundingClientRect() to implement scrolling and fixation of div containers. For more information, please follow other related articles on the PHP Chinese website!