Not long ago, a netizen who was about to graduate sent me an email. His graduation project needed to achieve a lock screen effect, but he could not understand the source code of the dialog box I posted before. He asked if he could explain the lock screen related code. I said I would post it in two days. Since I have been very busy recently, I only remembered it now, and I hope it is not too late to write this article.
Getting to the point:
Nowadays, full-screen semi-transparent mask layers are widely used in web2.0 websites. Most masks are implemented by calculating the page size and then covering it with a layer of the same size as the page, such as Tencent qzone and wordpress backend. This method is understandable, but it will fail under IE8 when the page is very long (the explanation from foreign information is that it is related to the machine's graphics card). Some students with perfect plots scratched their heads after encountering this problem. In desperation, they even I want IE8 to be forced to use the method of IE7 to parse his works. Actually we have a better way, let’s use CSS to solve it!
Remember " position:fixed "? It is a new attribute of CSS2. It can make an element stay still on the page and not move when dragging the scroll bar. For example, the fixed navigation bar at the top of Qzone is implemented in this way. Similarly, we can also use a layer with 100% height and width to cover the browser viewport, so that full-screen masking can be achieved. There is no need to calculate the size of the page, and there is no need to dynamically modify the size when resizing the browser.
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
But there is a headache. IE6 does not support "position: fixed". We can only dynamically modify its TOP value through js to simulate static positioning. When dragging the scroll bar, the mask will definitely shake because every time it changes IE will re-render again. But Microsoft has provided us with a very interesting feature. If you set a statically positioned background image for the html or body tag, the layer will not shake when the scroll bar is dragged, almost perfectly simulating "position:fixed" ". In actual projects, I found that this feature can also trigger other special functions, which I will explain later.
In order to save trouble, we use the evil expression to write some scripts in CSS for IE6, and reposition our mask layer when dragging the scroll bar. Legend has it that expression is very performance-intensive, but our expression has almost no loss. Interested students can study expression in depth.
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
Okay, after being compatible with the big-headed doll IE6, our lock screen mask has been adopted by mainstream browsers. However, students who use js to write effects are always very frustrated and always want to toss in something, so we will Add a little script to interrupt user operations when the screen is locked, disable the scroll bar, wheel, tab key, select all, refresh, and right-click to simulate a real 'lock screen':
Run code box
[Ctrl+A Select All Tips: You can modify part of the code first and then press Run]
Original text: http://www.planeart.cn/?p=792