2012-09-04 99 views
1

我一直在寻找这个插件http://benalman.com/code/projects/jquery-resize/examples/resize/,并可以使它正常工作,用于显示窗口的尺寸的例子。jQuery的调整大小插件的div

我想显示特定div的尺寸,当我尝试这样做时,页面加载时会显示尺寸,但不会因为div通过更改浏览器窗口来调整尺寸而更改尺寸。

我使用这个代码:

// Bind the resize event. When the window size changes, update its corresponding 
// info div. 
$('.main').resize(function(){ 
    var elem = $(this); 

    // Update the info div width and height 
    $('#main-dim').text('Main, width: ' + elem.width() + ', height: ' + elem.height()); 
}); 

// Updates the info div immediately. 
$('.main').resize(); 

}); 

.main是我想要得到的尺寸股利,#main-dim是div中显示的尺寸

谁能告诉我。我在这里做错了什么?

谢谢!

回答

0

环绕文档准备好块之间的代码:

<script> 
    $(document).ready(function(){ 
    // add code here 
    }); 
</script>