jquery - 仅在较小的屏幕上切换导航

标签 jquery html css resize toggle

我有一个菜单可以在大屏幕上完整显示。然而,对于 1024px 和 1400px 之间的屏幕,我希望隐藏作为此菜单一部分的社交图标,并且仅在单击按钮时显示它们。这工作正常,但在单击显示它们的按钮后,如果我将窗口调整为更宽的尺寸,按钮不再显示。理想情况下,当屏幕在 1024px 和 1400px 之间时,展开社交图标按钮将显示,允许我在单击该按钮时看到我的社交按钮,但是当将窗口调整到更大尺寸时,它应该自动隐藏展开社交图标按钮并显示它们除了单击展开社交图标按钮然后将窗口大小调整为更大的屏幕之外,社交按钮不会显示。

这是我的切换 jquery 代码:

jQuery.fn.clickToggle = function (a, b) {
  function cb() {
   [b, a][this._tog ^= 1].call(this);
  }
   return this.on("click", cb);
};

$(".header-social-trigger").clickToggle(function () {
  $('.header-social').css("cssText", "display: table-cell!important");
  $('.dg-button, .mnr-header-button').css("cssText", "display: none");
  $('.header-social-trigger .icon').removeClass("ion-android-share-alt");
  $('.header-social-trigger .icon').addClass("ion-close");
}, function () {
  $('.header-social').css("cssText", "display: none");
  $('.dg-button, .mnr-header-button').css("cssText", "display: table-cell");
  $('.header-social-trigger .icon').removeClass("ion-close");
  $('.header-social-trigger .icon').addClass("ion-android-share-alt");
});

我创建了一个 fiddle 来说明我在这里遇到的问题 https://jsfiddle.net/v5bgp389/18/ .我怎样才能基本上让代码忽略切换代码并在更大的屏幕上显示所有按钮?

最佳答案

/*Change Css*/
        @media screen and (max-width: 1024px) {
            .header-social-trigger {
                display: table-cell !important;
                background-color: #e0771a !important;
                border-left: 0 !important;
            }

                .header-social-trigger:hover {
                    background-color: #f1811e !important;
                }

            .header-social {
                display: none !important;
            }
        }

    @media screen and (min-width: 1024px) {
            .header-social-trigger {
                display:none !important;
                background-color: #e0771a !important;
                border-left: 0 !important;
            }

                .header-social-trigger:hover {
                    background-color: #f1811e !important;
                }

            .header-social {
                display: table-cell !important;
            }
        }

关于jquery - 仅在较小的屏幕上切换导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44885230/

相关文章:

css - 在使用 Razor 的 MVC 4 中,在 Microsoft 提供的用于更改文本框和下拉列表样式的默认 css(site.css) 中找不到类

javascript - jQuery - 动态改变 CSS

javascript - 为什么我的选择选项显示在 jquery UI 对话框后面?

javascript - 使用 jquery 是否可以在 div 中查找和替换字符串?

html - 对齐 div 边框和表格边框

html - 如何使div成为内联 block ?

javascript - 如何使用 javascript 为 webkit 滚动条编写 css?

html - Bootstrap 3 - 从模态对话框中删除下划线

javascript - 获取 DOM 中属性名称以 some-string 开头的所有 HTML 元素

javascript - 当在代码中使用 $(this) 时,人们如何命名它?