jQuery调整div上的侦听器大小 [英] jquery resize listener on a div

查看:267
本文介绍了jQuery调整div上的侦听器大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这种情况,我彼此相邻有2个div.一格的高度非常动态,这基本上意味着它可以增长和收缩以适应其内容.例如,此div的内容可以折叠打开或关闭,或者容器可以扩展以适合ajax加载的内容.

This is the situation, I have 2 div's next to each other. One div is very dynamic in height, which basically means it can grow and shrink to accommodate for it's content. For example, this div has content that can be folded open or close, or containers that can expand to fit ajax loaded content.

现在,此div旁边的另一个是整齐地跟随第一个div到CSS高度的div.效果很好.但这是一个问题:我想根据第二个div的高度更改其内容.

Now, next to this div is another one that neatly follows the height of the first one through css. Works great. But here is the question: I would like to change the content of this second div depending on its height.

换句话说,div 1的大小发生了变化,div 2跟随了CSS,现在我需要触发一个ajax调用以用新的内容重新填充div 2,使其适应新的大小.

In other words, div 1 changes in size, div 2 follows through css and I now need to trigger an ajax call to re-fill div 2 with new content, befitting it's new size.

有人知道如何使用jquery做到这一点吗?如果可能的话,不使用超时?

Has anybody an idea how I can do this with jquery? If possible, without the use of timeouts?

干杯.

推荐答案

As the thread poelinca provided suggests, there are some nice plugins available for this functionality.

如果您不喜欢插件的想法,另一种简单的解决方案是只要修改内容就在div上触发一个调整大小"事件.然后,您可以使用优雅的观察者模式,按照预期的那样使用resize()对其进行监视.. >

If you don't like the plugin idea, another simple solution would be to simply trigger a "resize" event on the div whenever the content is modified. Then you could monitor it with resize() as expected, utilizing an elegant observer pattern.

function appendContent($div, content) {
   $div.append(content).trigger($.Event('resize'));
}

$div.bind('resize', function(e) {
   // all your magic resize mojo goes here
});

这篇关于jQuery调整div上的侦听器大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆