さらにonResize

1 window.onresize = 関数(EV){
 2       はconsole.log( 'の寸法が変更された!' );
 3  };
 4  
5。 window.addEventListener( 'リサイズ'、関数(EV){
 6      はconsole.log(「の寸法が変更されています! " );
 7 });
1   * / 
2       画面が> = 960である場合、ページの背景色が赤幅;
 3       > = 640の画面幅ページの背景色が青色であり、
 4       画面640のように幅、背景<ページ色は緑ですか?
5      * / 
6。 
7。      window.addEventListener( '負荷'、関数(EV){
 8。         changeColor();
 9          // 1のリスニングウィンドウのサイズが変更された
10          window.addEventListener( 'リサイズ' 、changeColor);
 11  
12である         機能changeColor (EV1){
 13は、             IF(myTool.client()幅> = 960 ){
 14                  document.body.style.backgroundColor = '赤' 15             } そう であれば(myTool.client()幅> = 640 ){
 16                  document.body.style.backgroundColor = '青' 17              } {
 18                  document.body.style.backgroundColor = 'グリーン' 19              }
 20          }
 21      });
1   クライアント:関数(){
 2              であれば(window.innerWidth){ // IE9 +最新的浏览器
3                  リターン{
 4                      幅:window.innerWidth、
 5                      高さ:window.innerHeight
 6                  }
 7              } そう であれば(document.compatMode == = "CSS1Compat"){ // W3C 
8                  リターン{
 9                      幅:document.documentElement.clientWidth、
 10                      高さ:document.documentElement.clientHeight
 11                 }
 12              }
 13              リターン{
 14                  幅:document.body.clientWidth、
 15                  高さ:document.body.clientHeight
 16              }
 17          }

 

おすすめ

転載: www.cnblogs.com/zhangzhengyang/p/11210875.html