微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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()因滚动条而不同.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐