Ric*_*ich 23 javascript jquery window-resize
每当调整浏览器窗口大小时,如何调用此(或任何)JS函数?
<script type="text/javascript">
 function setEqualHeight(e) {
     var t = 0;
     e.each(function () {
         currentHeight = $(this).height();
         if (currentHeight > t) {
             t = currentHeight
         }
     });
     e.height(t)
 }
 $(document).ready(function () {
     setEqualHeight($(".border"))
 })
</script>
udi*_*idu 28
您可以使用窗口onresize事件:
window.onresize = setEqualHeight;
dou*_*ald 17
你可以订阅这个window.onresize活动(见这里)
window.onresize = setEqualHeight;
要么
window.addEventListener('resize', setEqualHeight);
Gab*_*oli 12
您使用jquery,因此使用该.resize()方法绑定它.
$(window).resize(function () {
    setEqualHeight( $('#border') );
});
小智 12
这段代码将添加一个定时器,在调整窗口大小200毫秒后调用resize函数.这将减少方法的调用.
var globalResizeTimer = null;
$(window).resize(function() {
    if(globalResizeTimer != null) window.clearTimeout(globalResizeTimer);
    globalResizeTimer = window.setTimeout(function() {
        setEqualHeight();
    }, 200);
});