js 控制div 元素 隨着窗口的變化,保持長寬比例不變

<script>
   $(document).ready(function(){
 window.onresize=function(){
   //第一種寫法
   $(".mapDiv").height($(".mapDiv").width()*0.31);
   //第二種寫法
   $(".mapDiv").css("height",$(".mapDiv").width()*0.31);
   //第三種寫法
   $(".mapDiv").css("height",$(".mapDiv").width()*0.31+"px");
   }
});
  </script>
相關文章
相關標籤/搜索