jQuery调整Div响应

我正在尝试制作一个脚本,它将在一定分辨率以上完成相同的高度函数.

一旦低于该分辨率,我希望脚本关闭,因为相同高度的列在网站的移动版本上消失.

我希望这也可以在resize上执行.到目前为止,这是我的代码.这根本不起作用.

拉伸功能在检查宽度功能之外进行了测试.

这是我的代码

原始拉伸功能

$(document).ready(function () {
    var $stretch = $(".eq");
    $stretch.animate({ height: $stretch.parent().height() },300 );
});

调整不起作用的功能

$(document).ready(function() {
    // Optimalisation: Store the references outside the event handler:
    var $window = $(window);
    var $stretch = $("#narrow")
    var $stretch2 = $(".eq")

    function checkWidth() {
        var windowsize = $window.width();
        if (windowsize > 440) {
            //if the window is greater than 440px wide then turn on jScrollPane..
            $stretch.animate({ height: $stretch.parent().height() },800 );
            $stretch.animate({ height: $stretch2.parent().height() },300 );                
        }
    }
    // Execute on load
    checkWidth();
    // Bind event listener
    $(window).resize(checkWidth);
});

我怎样才能做到这一点?

解决方法

对于jquery部分

$(window).resize(function() {
    // do your stuff here

    checkWidth();
});

如果您使用js组合的媒体查询,请记住媒体查询宽度和$(window).width()因滚动条而不同.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...