5/03/2017

[js] javascript onresize code

因為科技日新月異,開發專案常需要判斷不同瀏覽器大小,啓動不一樣的js function
而我們今天要講的是on resize事件,是非常好用的功能,當使用者改變視窗大小後
我們也能再一次的偵測視窗的尺寸,同事啓發不同的function讓畫面上有最好的安排
hi onresize function in javascript like that

window.onresize=function(){

//coding here

};



we also write a example code like this 
that can detact the width of site,than work different function
I always use it in my responsive web design project
hope this code is good for you


function _resize(){
    
     var h = $(window).width();
    //to know the width of web

  if (h > 1280){

     //alert('big1280');

     TweenMax.fromTo(".milkmidi_tweenmax_wrap", 0, {css: {}}, {css:{ scale:1.2,bottom:-0},delay:0,ease:"Expo.easeNone"} )

    }

    
  if (h < 1024){
    //alert('small,less than 1024');    

     TweenMax.fromTo(".milkmidi_tweenmax_wrap", 0, {css: {}}, {css:{ scale:0.8,bottom:-50},delay:0,ease:"Expo.easeNone"} )

    }

    
     }

//
_resize()


// if 
onresize do this function again
window.onresize=function(){    
    
_resize()
    
}



//---------------------------------------------------------------------


如果覺得我的文章有幫助,
請你點右邊的FB加入訂閱我會在粉絲團不定期分享新資訊
也歡迎交流!


阿特底賽粉絲團https://www.facebook.com/artdesigntw

No comments:

Post a Comment