简体   繁体   English

.toggle()函数添加溢出隐藏内联

[英].toggle() function adds overflow hidden inline

In the site that I'm working on, I am using the jQuery .toggle() function to display and hide the navigation when viewing the site in mobile devices. 在我正在工作的网站中,我使用jQuery .toggle()函数在移动设备中查看网站时显示和隐藏导航。 Here's the code that I am using: 这是我正在使用的代码:

<script>

   $(document).ready(function() {
            $('.nav-toggle').click(function(){
                //get collapse content selector
                var collapse_content_selector = $(this).attr('href');                   

                //make the collapse content to be shown or hide
                var toggle_switch = $(this);
                $(collapse_content_selector).toggle(function(){
                    if($(this).css('display')=='none'){
                        toggle_switch.html('Show');//change the button label to be 'Show'
                    }else{
                        toggle_switch.html('Hide');//change the button label to be 'Hide'
                    }
                });
            });

        }); 
</script>

It is toggling the navigation but the text links are not displaying. 它正在切换导航,但未显示文本链接。 I've used the element inspector in chrome and I'm seeing that overflow:hidden is being added inline to the element by the .toggle() function but it is not being removed when toggling to display the links. 我已经在chrome中使用了元素检查器,并且看到了溢出:.toggle()函数将内嵌式隐藏添加到元素中,但是在切换显示链接时并未将其删除。 I've taken a look at the jQuery documentation for this but it doesn't mention anything about overflow:hidden. 我已经看过有关jQuery的文档,但是没有提到关于overflow:hidden的任何内容。 You can see that this is being adding by this function because it does not appear until after clicking the toggle button 您可以看到此功能正在添加此功能,因为直到单击切换按钮后它才会出现

Here's the url to the site: http://theinfluence.iamchrisbarnard.com 这是该网站的网址: http : //theinfluence.iamchrisbarnard.com

The toggle function is being applied to the toggle icon in the top right but can only be seen at smaller sceensizes. 切换功能已应用于右上角的切换图标,但只能在较小的屏幕尺寸上看到。 And it's toggling the nav element at the very top of the page. 并且它在页面的顶部切换了nav元素。

What could be causing this issue? 是什么导致此问题?

Instead of making background image for the toggle menu try adding as image. 而不是为切换菜单制作背景图像,请尝试添加为图像。 Code something similar to 代码类似于

Html HTML

 <a href="javascript:void(0);" id="mobibtn" style="display:none;"><img src="images/icon_mobile_menu.jpg" alt="m"> Menu</a>

jQuery jQuery的

$(window).resize(function() {
var windowWidth = $(window).width();
if (windowWidth < 366) {
    $('#nav').hide();
    $('#mobibtn').show();

} else {
    $('#nav').show();
    $('#mobibtn').hide();
    $('#mobimenu').hide();
}
});

$(window).load(function() {
var windowWidth = $(window).width();
if (windowWidth < 366) {
    $('#nav').hide();
    $('#mobibtn').show();

} else {
    $('#nav').show();
    $('#mobibtn').hide();
    $('#mobimenu').hide();
}
});

$(document).ready(function() {
$('#mobibtn').click(function() {
     $('#mobimenu').toggle();
});
});

(You may see live example at http://pfitr.net/frontend/index.html ) (您可能会在http://pfitr.net/frontend/index.html上看到实时示例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM