javascript - Position sticky -
i know it's great web developers can accomplish things without js:
.sticky { position: -webkit-sticky; position: -moz-sticky; position: -ms-sticky; position: -o-sticky; top: 15px; } vs
<style> .sticky { position: fixed; top: 0; } .header { width: 100%; background: #f6d565; padding: 25px 0; } </style> <div class="header"></div> <script> var header = document.queryselector('.header'); var origoffsety = header.offsettop; function onscroll(e) { window.scrolly >= origoffsety ? header.classlist.add('sticky') : header.classlist.remove('sticky'); } document.addeventlistener('scroll', onscroll); </script> but under hood of actual browser isn't doing same kind of rendering, , take same amount of memory. in essence there lower level of code in browser renders css finds position: -webkit-sticky, , of same rendering javascript above?
in essence there lower level of code in browser renders css finds position: -webkit-sticky, , of same rendering javascript above?
no. browser not have same thing.
with native support sticky regions, each clipped region browser can maintain 2 separate graphics buffers -- 1 non-sticky content sized container , 1 sticky content sized viewport. on scroll, it
- grabs visible region of first,
- composite second (taking account z-indices)
- blits screen.
the browser not need deal dom @ all.
compare js onscroll approach.
- grab lock in case js frame computing in current frame
- set js execution context
- run user function
- check whether css selectors need re-applied
- check whether dom needs laid out
- check whether dom modification event listeners need fired
- figure out bits of dom need re-rendered -- isn't matter of moving around rectangles have been rendered
- re-render
- composite
- blit
Comments
Post a Comment