jQuery: 停止window高度重新计算一次条件语句returns false

jQuery: Stop window height recalclulation once conditional statement returns false

我有一个 jQuery 函数,它可以在满足某些条件时更改列的大小。一旦调整了 window 的大小,该函数就会开始工作。但是一旦条件 return false 就不会停止重新计算。 怎么解决? 这是一个脚本:

jQuery(document).ready(function ($) {

    element_second = document.getElementsByClassName('second_column')[0];
    element = document.getElementsByClassName('first_column_main_page')[0];


    $(window).on('resize', function(){      
        interval = setInterval(updateHeight,3000);
    });


  function updateHeight(){    

    var $window = $(window);
    var width = $window.width();
    var height = $window.height();
        if (height > 667 && height < 800) {
            interval = setInterval(updateHeight,300);
            console.log('true');
            setInterval(function () {
                if ((width != $window.width()) || (height != $window.height())) {
                    width = $window.width();
                    height = $window.height();

                    element.style.height = ((height - element.offsetTop) + "px");
                    element_second.style.height = ((height - element.offsetTop) + "px");    
                }
            }, 300);
        } 
        else {
            console.log('false');
            clearInterval(interval);        
            element.style.height = (840 + "px");//
            element_second.style.height = (840 + "px");// this part makes all blocks to flash, cause recalculations dosn's stop
        }            
  };            
});

换句话说,我需要一个脚本来重新计算特定尺寸的高度。

@Titus 回答:

 jQuery(document).ready(function ($) {


    element_second = document.getElementsByClassName('second_column')[0];
    element = document.getElementsByClassName('first_column_main_page')[0];


    $(window).on('resize', function(){      
        updateHeight();
    });


  function updateHeight(){    

        var $window = $(window);
        var width = $window.width();
        var height = $window.height();

        if (height > 667 && height < 800) {

            console.log('true');

{
                width = $window.width();
                height = $window.height();

                element.style.height = ((height - element.offsetTop) + "px");
                element_second.style.height = ((height - element.offsetTop) + "px");    


        } 
        else {
            console.log('false');                   
        }            
  };    

});

@Titus 回答:

 jQuery(document).ready(function ($) {


    element_second = document.getElementsByClassName('second_column')[0];
    element = document.getElementsByClassName('first_column_main_page')[0];


    $(window).on('resize', function(){      
        updateHeight();
    });


  function updateHeight(){    

        var $window = $(window);
        var width = $window.width();
        var height = $window.height();

        if (height > 667 && height < 800) {

            console.log('true');

{
                width = $window.width();
                height = $window.height();

                element.style.height = ((height - element.offsetTop) + "px");
                element_second.style.height = ((height - element.offsetTop) + "px");    


        } 
        else {
            console.log('false');                   
        }            
  };    

});