Home  >  Article  >  Web Front-end  >  How to use getBoundingClientRect() to implement scrolling and fixation of div containers

How to use getBoundingClientRect() to implement scrolling and fixation of div containers

php中世界最好的语言
php中世界最好的语言Original
2018-02-23 10:25:502261browse

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:

What are the differences between the standard writing method of html and the code generated by Dreamweaver

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Why does z-index fail?Next article:Why does z-index fail?