首页 > 解决方案 > 调整窗口大小不适用于 JQuery 函数 - 需要刷新窗口

问题描述

我正在设计一个响应式网站,并且有一些 JQuery 功能需要适应网站窗口的大小调整。但是,由于某些原因,某些功能无法调整。

这是一个函数的例子:

function navigate(bottom, top, topbottom, position) {
            $(document).on("mouseleave", top, function() {
                if ($(bottom).is(':visible')) {
                } else {
                    $(bottom).show();
                }
                if ($(bottom).is(":hover")) {
                } else {
                    $(bottom).hide();
                }
            });
            $(document).on("mouseleave", bottom, function() {
                if ($(top).is(":hover")) {
                } else {
                    $(bottom).hide();
                }
            });

            var width = $(window).width();
            if (width <= 768) {
                $(document).on("mouseover", top, function() {
                    var top_2 = 50;
                    $(bottom).show();
                    $(".bottom_navigation").css({"top": top_2 * (position + 1)})
                });
            } else if (width > 768) {
                $(document).on("mouseover", top, function() {
                    var left = $(top).width();
                    $(bottom).show();
                    $(".bottom_navigation").css({"left": left * position})
                });
            }
        }

我也尝试过这样的事情:

    $(window).on("resize", function() {
       //function here!

    });

任何人都可以提出解释,以便我理解这种现象并可能提出解决方案吗?

标签: jquery

解决方案


推荐阅读