Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

z-index, how does it affect performance?

How does the css z-index value affect performance?

If I have multiple images on a page does it matter if I use high z-index values, like 10,000?

For example, a page contains 15 images with z-indexes ranging from 500 - 10,000, and if the images are moveable (jQuery draggable), does it impact upon performance by using high values if the page is redrawn so frequently?

like image 478
walden Avatar asked May 04 '11 17:05

walden


1 Answers

The number of layers matters, but the actual value of the z-index does not. When rendering the page, the browser just sorts all of the absolutely-positioned elements by their z-index (ascending) and draws them in that order.

EDIT: Also, the performance hit from sorting only occurs when you change the z-index of the layers. If the z-indices aren't changing often, the performance hit probably won't be noticeable at all. Even if you are changing the z-indices a lot, sorting a list of 15 items is almost instantaneous.

like image 54
lazycs Avatar answered Oct 06 '22 00:10

lazycs