单击链接时,rails jquery脚本不起作用

米沙

我发现了一个jquery脚本,使div具有相等的高度。它使用window.load和window.resize调用该函数。当我加载页面或调整页面大小时,它可以工作,但是,如果我通过站点上的链接转到页面,则div会再次变为其旧高度。我认为这与rails turbolinks(类似于具有turbolinks和window load的rails 4)有关,但是我无法使其正常工作(即使与链接中的解决方案有关)。这是脚本(它是通过资产管道加载的

equalheight = function(container){

  var currentTallest = 0,
    currentRowStart = 0,
    rowDivs = new Array(),
    $el,
    topPosition = 0;
  $(container).each(function() {
    $el = $(this);
    $($el).height('auto')
    topPostion = $el.position().top;

    if (currentRowStart != topPostion) {
      for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
        rowDivs[currentDiv].height(currentTallest);
      }
      rowDivs.length = 0; // empty the array
      currentRowStart = topPostion;
      currentTallest = $el.height();
      rowDivs.push($el);
    } else {
      rowDivs.push($el);
      currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
    }
    for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
      rowDivs[currentDiv].height(currentTallest);
    }
  });
}

$(window).load(function() {
  equalheight('.container-fluid box');
});

$(window).resize(function(){
  equalheight('.container-fluid box');
});
用户名

用这个 :-

$(document).on('ready page:load', function() {
    equalheight('.container-fluid box');
})

或这个 :-

$(document).on('ready', function() {
    equalheight('.container-fluid box');
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

构建应用程序捆绑包时gradle脚本不起作用

单击时,django下拉项超链接不起作用

jQuery on('click')在单击时不起作用

Javascript:动态创建菜单时,菜单脚本不起作用

在Heredoc中传递给SSH时,Awk脚本不起作用

文件名中的空格时,批处理图像转换的脚本不起作用

通过ajax加载时,tweet按钮脚本不起作用

当我尝试执行postcodeanywhere脚本时,自动完成脚本不起作用

使用case语句进行决策时,bash脚本不起作用

jQuery中的链接使其他脚本不起作用

单击链接时Ajax不起作用,为什么?

从另一个目录调用脚本时,脚本不起作用

当我在MVC4中使用Datepicker jQuery脚本时用于调用操作的脚本不起作用

jQuery附加链接(链接“单击”不起作用)

使用'#!/ bin / sh'运行脚本时,该脚本不起作用

用户键入空格时,Windows脚本不起作用

通过-c传递到bash时脚本不起作用

选择的jQuery脚本不起作用

从公式获取值时脚本不起作用

尝试登录时,我的 php/mysql 脚本不起作用

简单的 jQuery 脚本不起作用

当通过外部文件获取时,react 脚本不起作用

推送到设备时,Shell 脚本不起作用

我的 jquery 脚本不起作用

使用 JQuery 脚本和 Bootstrap 时链接不起作用

为什么单击此 JQuery 脚本中的按钮时此单击事件不起作用?

当我在列表中查找多个搜索关键字时,脚本不起作用

包含在 Jenkins 管道脚本中时,Powershell 脚本不起作用

当路径具有特殊字符时,包含脚本不起作用