Application of floating layer in PHP

Source: Internet
Author: User

1) PHP test page code

<Table cellpadding = "0" cellspacing = "0" border = "0" width = "100%"> <br/> <tr> <br/> <TD class = "None "width =" 45% "> <br/> <input type =" text "name =" txtprogram "class =" textbox "/> <br/> </TD> <br /> <TD class = "NONE"> <br/> <a class = "button" href = "#" mce_href = "#" id = "btnprogram" name = "btnprogram "onclick =" displaydiv ('project ', this) "> <br/> <span> selection </span> <br/> </a> <br/> </TD> <br/> </tr> <br/> <tr> <br/> <TD class = "NONE" colspan = "2" style = "border-right: 0px; border-bottom: 0px "mce_style =" border-Right: 0px; border-bottom: 0px "> <br/> <Div id =" program "style =" filter: alpha (opacity = 75); position: absolute; Z-index: 100; display: none; Background-color: # e2eef3 "mce_style =" filter: alpha (opacity = 75 ); position: absolute; Z-index: 100; display: none; Background-color: # e2eef3 "> <br/> floating layer to be tested <br/> </div> <br/> </TD> <br/> </tr> <br/> </table>

Several key factors of floating layer definition: Z-index: 100; display: none;

2) The floating layer is displayed when I need to click the button below, and the floating layer is on the right of the button. I will introduce how to obtain the Coordinate Position of an element in the next blog. Now we only need to directly reference the getelementpos function to obtain the coordinate of an element.

/** <Br/> * display the floating layer <br/> * @ Param STR the id value of the floating layer <br/> * @ Param value <br/> */<br/> function displaydiv (STR, value) <br/>{< br/> floatarea = document. getelementbyid (STR); <br/> If (floatarea. style. display = "NONE") <br/>{< br/> floatarea. style. border = "# cde699 1px solid"; <br/> var Pos = getelementpos (value. ID); <br/> X = POS. x; <br/> Y = POS. y; <br/> floatarea.style.left.pdf (document.doc umentelement. scrollleft + x + 65) + "PX"; <br/> floatarea.style.top((document.doc umentelement. scrolltop + Y + 1) + "PX"; <br/> floatarea. style. width = "300px"; <br/> floatarea. style. display = ""; <br/>}< br/> else <br/>{< br/> closefloat (STR); <br/>}< br/>}

3) There are many ways to close the floating layer. First, click the button to close the floating layer. Determines whether the floating layer is in the none status. If not, the closed function is called directly.

/**
* Close the floating layer
* @ Param STR the id value of the floating layer
*/
Function closefloat (STR)
{
Floatarea = Document. getelementbyid (STR );
Floatarea. style. Display = "NONE ";
}

4) if I want to disable it through a button on the floating layer. You can add a close button between the DIV of the floating layer and trigger the closefloat function.

<Div id = "close" style = "position: absolute; Right: 10px; top: auto; left: auto; bottom: 0px; "> <input name =" img1 "id =" img1 "type =" image "width =" 20px "Height =" 20px "src =" images/close_float.gif "onclick =" closefloat ('signature '); "> </div>

5) if there are many dynamically generated floating layers on your page, you want to clear the previous floating layer before another floating layer appears, because you cannot predict user operations, you are not sure which floating layer appears first.

First, define a hidden field on the PHP page: <input type = "hidden" name = "hiddivs" id = "hiddivs" value = "{0: Program, 1: program1, 2: program2, 3: program3, 4: program4} ">

Add the following at the beginning of the displaydiv function:

VaR hiddivs = Document. getelementbyid ("hiddivs ");
If (hiddivs! = NULL ){
Eval ("Var divs =" + hiddivs. value );
For (var I in divs ){
If (divs [I]. ID! = Document. getelementbyid (STR). Id)
Divs [I]. style. Display = "NONE ";
}
}

Locate all floating layers except the current floating layer and disable them.

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.