Creating Web page Skills: Customizing the page with JavaScript

Source: Internet
Author: User
Tags window
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.



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.