Implement style and behavior separation in lightBox. Reduce the JS_javascript skill to center a single row. Multiple rows are left unknown and vertically centered.

Source: Internet
Author: User
This tutorial aims to achieve the separation of style and behavior in lightBox, reducing JS's work in various aspects (full screen masking, select masking in ie6, bidirectional center, highly adaptive content, etc. This tutorial aims to achieve the separation of style and behavior in lightBox, reducing JS's work in various aspects (full screen masking, select masking in ie6, bidirectional center, highly adaptive content, etc.

First run the Code:

   
  
  
  LightBox with full screen shielding and Automatic Center    

Text center when the prompt is smaller than one line [br]

When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br] When the content has exceeded the height of a screen, the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br] the content has exceeded the height of a screen. the content exceeds the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen, and the content exceeds the height of a screen. [br] When the content exceeds the height of a screen. When the content has exceeded the height of a screen, the content has exceeded the height of a screen, and the content has exceeded the height of a screen. [br] When the content has exceeded the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen, and the content exceeds the height of a screen. [br] When the content exceeds the height of a screen screen height: when the content has exceeded the height of a screen, when the content has exceeded the height of a screen, when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen when the content has exceeded the height of a screen, when the content has exceeded the height of a screen, when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen height: the content has exceeded the height of a screen; the content has exceeded the height of a screen. [br] the content has exceeded the height of a screen. when the content has exceeded the height of a screen, when the content has exceeded the height of a screen, when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen the content has exceeded the height of a screen. When the content has exceeded the height of a screen, the content has exceeded the height of a screen. [br] When the content has exceeded the height of a screen the content has exceeded the height of a screen. When the content has exceeded the height of a screen, [br] When the content has exceeded the height of a screen the content exceeds the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen. [br] When the content exceeds the height of a screen, the content exceeds the height of a screen. the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen. [br] When the content exceeds the height of a screen, the content exceeds the height of a screen. the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen. [br] When the content exceeds the height of a screen, the content exceeds the height of a screen. screen height when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen when the content has exceeded the height of a screen when the content has exceeded the height of a screen, when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen, when the content has exceeded the height of a screen height: when the content has exceeded the height of a screen, when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen, when the content has exceeded the height of a screen when the content has exceeded the height of a screen, when the content has exceeded the height of a screen [br] When the content has exceeded the height of a screen, when the content has exceeded the height of a screen the content has exceeded the height of a screen. When the content has exceeded the height of a screen, [br] When the content has exceeded the height of a screen, when the content has exceeded the height of a screen. the content has exceeded the height of a screen. When the content has exceeded the height of a screen, [br] When the content has exceeded the height of a screen, when the content has exceeded the height of a screen the content exceeds the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen. When the content exceeds the height of a screen, the content exceeds the height of a screen. when the content has exceeded the height of a screen [br]

Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]

Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]A select statement used to test whether Internet Explorer 6 can overwrite Internet Explorer 6.[Br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]Another select statement is used to test whether Internet Explorer 6 can overwrite Internet Explorer 6.[Br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br]

Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br]

Script function showLayer (id) {document. getElementById (id ). style. display = "block";} function hideLayer (id) {document. getElementById (id ). style. display = "none";} script

This lightBox has the following features. You can test it by modifying the code ^-^:
The screen can be completely masked by clicking any position on the page (at this time, it is impossible to directly control any elements including the scroll bar ), the select element can be masked without hiding in IE6 (iframe masking: After masking, if you drag the scroll bar, select will still be moved to the top layer ).
LightBox highly adapts its content and presents a perfect center state.
When the content is a single row, it is displayed in the center; when the content is multiple rows, it is displayed in the left; The content height makes the scroll bar appear when the lightBox exceeds the screen, and displays it in the top, so that readers can fully read it.
If you are interested, you can refer to the following tips for creating this lightBox:

1. Full Screen masking:

A. Hide the html/body scroll bar.
B. Use a p as the mask and a p as the page with a scroll bar.

   
  
  
  Full Screen masking    

Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] Pretend to be rich in content [br] pretend to be rich in content [br]

2. single-row center, multi-row center-left method (see the demo and the presentation capability is limited ):

   
  
  
  Center a single row, left multiple rows    

When the content is small

Content is always time, time, and time from time to time from time to time from time to time, from time to time, from time to time

3. Use inline-block to implement vertical center of unknown heights (see the figure and demo, with limited presentation capabilities ):

Figure:

Code Demonstration:

   
  
  
  Method for vertical center of unknown height    






There are two details:
You can see that font-size: 0 is not displayed in the complete demo, but in the vertical center method.
Because font-size: 0 in the complete demo will make firefox3.5 readers complete reading the lightBox mouse wheel failure, the reason is unknown, you can deal with this situation.
MaxHeight can only be placed behind lightBoxContent, because bug and issue may occur in opera9.6.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.