JQuery如何监听一个DIV宽高的变化?
1个回答
展开全部
给你推荐一个jquery重新封装resize代码,可以监听几乎所有html标签,比如text、p、div、span等。$(function(){
// Bind the resize event. When any test element's size changes, update its
// corresponding info div.
$('.test').resize(function(){
var elem = $(this);
// Update the info div width and height - replace this with your own code
// to do something useful!
elem.closest('.container').find('.info')
.text( this.tagName + ' width: ' + elem.width() + ', height: ' + elem.height() );});// Update all info divs immediately.
$('.test').resize();
// Add text after inline "add text" links.
$('.add_text').click(function(e){
e.preventDefault();
$(this).parent().append( ' Adding some more text, to grow the parent container!' );});// Resize manually when the link is clicked, but only for the first paragraph.
$(this).parent().resize();});});看一下官方介绍吧,里面有几个例子!jquery resize event
// Bind the resize event. When any test element's size changes, update its
// corresponding info div.
$('.test').resize(function(){
var elem = $(this);
// Update the info div width and height - replace this with your own code
// to do something useful!
elem.closest('.container').find('.info')
.text( this.tagName + ' width: ' + elem.width() + ', height: ' + elem.height() );});// Update all info divs immediately.
$('.test').resize();
// Add text after inline "add text" links.
$('.add_text').click(function(e){
e.preventDefault();
$(this).parent().append( ' Adding some more text, to grow the parent container!' );});// Resize manually when the link is clicked, but only for the first paragraph.
$(this).parent().resize();});});看一下官方介绍吧,里面有几个例子!jquery resize event
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询