Override the onresize and onscroll functions of the body

Source: Internet
Author: User

[Body] javascript Functions related to the body page. onload is triggered when the page is loaded, onresize is triggered when the page size changes, and onscroll is triggered when the scroll bar is rolled, in actual use, you do not want to add multiple trigger functions to the body, so you want to overwrite javascript as follows:

<SCRIPT language = javascript>
<! --
Function load_func (){
Window. onresize = func ();
Window. onscroll = func (); // func () indicates the function to be called.
}
// -->
</SCRIPT>

<body onload="load_func()">

In this way, only the onload function is used in the definition of the body to call load_func () and then overwrite other page events of the body. In IE, it can be used normally, but it does not work in Firefox, after checking for a long time, I thought that this overwrite method could not be implemented for Firefox, But I occasionally found that an overwrite code can be executed in FF. I checked it carefully and found that the overwrite method was different, compare the differences between the two:

Window. onresize = func (); // only supports IE

Window. onresize = func; // supports IE and FF

In Javascript, calling a function is generally represented by the function name + parentheses. However, only the function name is used to point to the defined function, but it is not supported by adding parentheses. I still don't know the specific cause, so you need to pay attention to it in the future.

 

 

This article is from: Jedliu.cublog.cn

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.