百转千回,万物皆变心不动,任清风自流。

html,css,jQuery,javascript,php,mysql,dedecms,phpcms,wordpress,linux,windows
  首页  :: 订阅 订阅  :: 管理

jquery实现div自适应浏览器高度(宽度)

Posted on 2012-07-12 15:59  李潇喃  阅读(5394)  评论(0)    收藏  举报
<!DOCTYPE html> <html> <head> <meta charset=UTF-8 /> <title>jquery实现div自适应浏览器高度(宽度)</title> <meta name="keywords" content="html5" /> <meta name="description" content="html5 test" /> <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <script type="text/javascript"> function autoHeight() { var h = $(window).height(); var h_old = 300; if (h > h_old) { $(".left").css('height', h); } else { return false; } } $(function() { autoHeight() $(window).resize(autoHeight); }) </script> <style type="text/css"> html, body { margin: 0; height: 100%; } .left { width: 100px; background: #E8EFF6; margin-left: 100px; } </style> </head> <body> <div class="left"> das </div> </body> </html>