Javascript| Skills | page | page | adaptive
Sometimes, we may need to be like the new Yahoo mailbox, so that some data display blocks can be adapted to the size of the page. The fact is not difficult, but if the simple use of CSS control, often can not fully realize the effect we want, this time need to use javascript,javascript can let me realize sikong the Adaptive page, in Isunxoft HR open source project applied to.
Implementation principle:
Get the wide height of the IE display screen. Determine which objects are absolute positions that are fixed, those that are not fixed, which are fixed, and then like the Win form program, the size of the root software interface, the design of the object's length, the absolute position, etc. But on the web, there is no way to detect the window's size change in real time, only by using the SetTimeout function to make an adaptive recursive call.
The following is an excerpt from the Isunxoft HR Open Source project Sysform.aspx implementation method.
Note: $ ("") is a variable element.
var h;
var W;
function Resize ()
{
var he = Document.body.offsetHeight;
var wi = document.body.offsetWidth;
if ($ ("DataTable"). Style.display.toLowerCase () = = "" | | $ ("DataTable"). Style.display.toLowerCase () = = "inline")
{
if (H==HE&&W==WI)
{
if ($ ("Leftmenu"). Style.display.toLowerCase () = = "None")
{
$ ("Divdatalist"). Style.width = wi-30;
}
Else
{
$ ("Divdatalist"). Style.width = wi-223;
}
SetTimeout ("Resize ()", 1000);
Return
}
h = he;
W = WI;
if (he>100)
{
$ ("Divdatalist"). Style.height = he-172;
}
if (wi>200)
{
$ ("Divdatalist"). Style.width = wi-223;
if ($ ("Leftmenu"). Style.display.toLowerCase () = = "None")
{
$ ("Divdatalist"). Style.width = wi-30;
}
}
}
if ($ ("Dataempwidows"). Style.display.toLowerCase () = = "Inline" | | $ ("Dataempwidows"). Style.display.toLowerCase () = = "")
{
if (H==HE&&W==WI)
{
if ($ ("Leftmenu"). Style.display.toLowerCase () = = "None")
{
$ ("Dataempwidows"). Style.width = wi-30;
}
Else
{
$ ("Dataempwidows"). Style.width = wi-223;
}
}
h = he;
W = WI;
if (he>150)
{
$ ("Dataempwidows"). Style.height = he-132;
}
if (wi>200)
{
$ ("Dataempwidows"). Style.width = wi-223;
if ($ ("Leftmenu"). Style.display.toLowerCase () = = "None")
{
$ ("Dataempwidows"). Style.width = wi-30;
}
}
}
if (typeof ($ ("eipwindows"))!= "undefined")
{
if ($ ("Eipwindows"). Style.display.toLowerCase () = = "inline")
//{
if (H==HE&&W==WI)
// {
if ($ ("Leftmenu"). Style.display.toLowerCase () = = "None")
// {
$ ("Eipwindows"). Style.width = wi-30;
// }
Else
// {
$ ("Eipwindows"). Style.width = wi-223;
// }
// }
h = he;
W = WI;
if (he>150)
// {
$ ("Eipwindows"). Style.height = he-132;
// }
if (wi>200)
// {
$ ("Eipwindows"). Style.width = wi-223;
if ($ ("Leftmenu"). Style.display.toLowerCase () = = "None")
// {
$ ("Eipwindows"). Style.width = wi-30;
// }
// }
//}
}
SetTimeout ("Resize ()", 1000);
}
Resize ();
The resize () is then invoked on the Web page, and once the window is changed or the resolution is changed, it ensures that the true sense of adaptation can be achieved.