Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
脚本不适用于jQuery 1.9.0_Jquery_Syntax_Incompatibility_Jquery 1.9 - Fatal编程技术网

脚本不适用于jQuery 1.9.0

脚本不适用于jQuery 1.9.0,jquery,syntax,incompatibility,jquery-1.9,Jquery,Syntax,Incompatibility,Jquery 1.9,以下脚本在加载和调整窗口大小时为特定容器中的div提供相等的高度。它来自 它可以在加载时工作,但在jQuery1.9.0中,该函数不适用于窗口大小调整。如果我将jQuery版本更改为1.5.0,则可以调整大小。我使用了jQueryMigrate插件,但它没有给出任何警告或错误。是否与1.9.0语法不兼容?有什么想法吗 // these are (ruh-roh) globals. You could wrap in an // immediately-Invoked Function Expre

以下脚本在加载和调整窗口大小时为特定容器中的div提供相等的高度。它来自

它可以在加载时工作,但在jQuery1.9.0中,该函数不适用于窗口大小调整。如果我将jQuery版本更改为1.5.0,则可以调整大小。我使用了jQueryMigrate插件,但它没有给出任何警告或错误。是否与1.9.0语法不兼容?有什么想法吗

// these are (ruh-roh) globals. You could wrap in an
// immediately-Invoked Function Expression (IIFE) if you wanted to...
var currentTallest = 0,
    currentRowStart = 0,
    rowDivs = new Array();

function setConformingHeight(el, newHeight) {
    // set the height to something new, but remember the original height in case things change
    el.data("originalHeight", (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight")));
    el.height(newHeight);
}

function getOriginalHeight(el) {
    // if the height has changed, send the originalHeight
    return (el.data("originalHeight") == undefined) ? (el.height()) : (el.data("originalHeight"));
}

function columnConform() {

    // find the tallest DIV in the row, and set the heights of all of the DIVs to match it.
    $('.equalize > .col').each(function() {

        // "caching"
        var $el = $(this);

        var topPosition = $el.position().top;

        if (currentRowStart != topPosition) {

            // we just came to a new row.  Set all the heights on the completed row
            for(currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

            // set the variables for the new row
            rowDivs.length = 0; // empty the array
            currentRowStart = topPosition;
            currentTallest = getOriginalHeight($el);
            rowDivs.push($el);

        } else {

            // another div on the current row.  Add it to the list and check if it's taller
            rowDivs.push($el);
            currentTallest = (currentTallest < getOriginalHeight($el)) ? (getOriginalHeight($el)) : (currentTallest);

        }
        // do the last row
        for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) setConformingHeight(rowDivs[currentDiv], currentTallest);

    });

}


// Dom Ready
// You might also want to wait until window.onload if images are the things that
// are unequalizing the blocks
$(function() {
    columnConform();
});


//  Window resize functions 
$(window).resize(function() {
columnConform();
});
//这些是(ruh-roh)globals。你可以把它包起来
//如果您想。。。
var=0,
currentRowStart=0,
rowDivs=新数组();
功能设置符合高度(el,新高度){
//将高度设置为新的高度,但记住原始高度以防发生变化
高程数据(“原始高度”),(高程数据(“原始高度”)==未定义)?(高程()):(高程数据(“原始高度”));
标高高度(新高度);
}
函数原始高度(el){
//如果高度已更改,请发送原始高度
返回(el.data(“原始高度”)==未定义)?(el.height()):(el.data(“原始高度”));
}
函数columnConform(){
//找到行中最高的DIV,并将所有DIV的高度设置为与之匹配。
$('.equalize>.col')。每个(函数(){
//“缓存”
var$el=$(本);
var topPosition=$el.position().top;
if(currentRowStart!=topPosition){
//我们刚来到一个新的一排。在完成的一排上设置所有的高度
对于(currentDiv=0;currentDiv
我认为您的问题在于使用
数据()。在jQuery 1.9.0中,元素的
data-*
属性中保存的值只有在第一次使用
data()
在DOM中遍历元素时才会读取


不要使用
data('originalHeight)
,而是使用
attr('data-originalHeight')
,因为这将在每次调用时重新读取该值。

console是否显示任何错误?我制作了一个JSFIDLE,jQuery 1.9.1在调整大小方面没有任何问题,但仍然无法处理我的代码,而console显示没有错误。脚本使用数据存储元素的高度,而不是作为html5属性。您的建议为元素添加了一个数据属性,不幸的是,这并不能解决问题。我制作了一个JSFIDLE,它可以与1.9.1一起使用,但在我的代码中仍然存在问题。我想不出来。我接受这个答案,因为它指出了剧本的正确方向;t更新元素的高度。我在这里找到了一个更好的修改脚本!谢谢