zoukankan      html  css  js  c++  java
  • jQuery实现布局高宽自适应

    在页面布局(layout)时经常是上左右的框架布局并且需要宽、高度的自适应,静态的div+css是无法实现,但是利用jQuery比较容易实现浏览器的兼容性,所以需要js来辅助。

    主要通过 jQuery.resize() 这个方法,也就是当窗口大小改变时重新计算布局的高宽。

    Html代码

    <div id="header"></div>  
    <div id="left"></div>  
    <div id="right"></div>  

    Js代码

    $(document).ready(function() {
        initLayout();
        $(window).resize(
    function() {
            initLayout();
        });
    });


    function initLayout() {
        $(
    '#right').width(document.documentElement.clientWidth - $("#left").width() - 2);
        
    var h = document.documentElement.clientHeight - $("#header").height() - 30;
        $(
    '#left').height(h);
        $(
    '#right').height(h-20);
    }
  • 相关阅读:
    Slimer软工课设日报-2016年6月30日
    Slimer软工课设日报-2016年6月29日
    软件工程个人总结
    什么是Bug
    构建之法读后感----第1章 绪论
    7.4
    7.1-7.3
    6.29
    软件工程课设 第二天
    软工总结 作业
  • 原文地址:https://www.cnblogs.com/greatandforever/p/1838512.html
Copyright © 2011-2022 走看看