简体   繁体   English

尝试编写JavaScript以隐藏切换侧菜单类,直到页面加载完毕。 当前显示一秒钟,直到页面加载

[英]Trying to write javascript to hide toggle side menu class until page is loaded. It currently shows for a split second until page loads

EDIT- Got it figured out, answer is below, thanks everyone! 编辑-弄清楚了,答案在下面,谢谢大家!

I'm back with another head scratcher that I've been working on all morning and can't seem to solve on my own and was hoping someone would help out this rookie. 我又回来了,整个上午我一直在努力工作,似乎无法独自解决,并希望有人能帮上这个菜鸟。

I currently have a problem with my phpbb forum when in responsive mode on my phone (can't duplicate it on desktop using mobile view, but it is happening on my phone and I assume most other phones since mine isn't much different than any other android). 我目前在手机上处于响应模式时,我的phpbb论坛存在问题(无法使用移动视图在桌面上复制它,但这是在我的手机上发生的,我认为大多数其他手机,因为我的手机与其他手机没有太大区别)其他android)。

So my problem is that my toggle side menu is loading before I would like it to. 所以我的问题是,在我想要切换之前,我的切换菜单正在加载。 The easiest way to explain is with a picture I made (couldn't screenshot it because it doesn't stay long enough). 解释的最简单方法是使用我制作的照片(由于无法保留足够长的时间而无法截图)。

模拟我的问题

As you can see, for about a second (or fraction of a second, just long enough to bug me), the header expands and the menu items are visible. 如您所见,大约一秒钟(或不到一秒钟的时间,足以使我烦恼),标题展开并且菜单项可见。 It doesn't show exactly as it would if the toggle was activated, for some reason, only the text and border items are visible. 它不完全像激活切换开关那样显示,由于某种原因,只有文本和边框项目可见。 The background color does stay hidden. 背景颜色不会隐藏。 The background of the header does expand with the text, which is shouldn't do with when the toggle is activated, so I'm not exactly sure what I need to do, hoping I can get some help. 标头的背景确实会随文本扩展,这在激活切换开关时不应该这样做,因此我不确定自己需要做什么,希望能得到一些帮助。

I didn't just come here hoping someone could do this for me, I've tried many many options. 我不仅仅是来这里希望有人能为我做这件事,我还尝试了很多选择。

I saw a similar question where it was advised to use #selector within the .css, but I had no luck with that. 我看到了一个类似的问题,建议在.css中使用#selector,但是我对此并不走运。

I've tried this script code: 我已经尝试过以下脚本代码:

<script type="text/javascript">
// Short-form of `document.ready`
$(function(){
    $(".gf-menu-device-container").hide();
    $(".gf-menu-toggle").on("click", function(){
        $(".gf-menu-device-container").toggle();
    });
});
</script>

The code does nothing for me. 该代码对我没有任何帮助。 I've also tried substituting .gf-menu-device-wrapper-sidemenu but nothing with that either. 我也试过用.gf-menu-device-wrapper-sidemenu代替,但都没有。

Here's the html code for that menu, The javascript file is minified and nearly impossible for me to get anything out of, but if anyone would like to look at it, it's here: https://raiderforums.com/styles/corvus/template/rt_js/mootools-core.js 这是该菜单的html代码,该javascript文件已缩小,几乎让我无法取出任何东西,但如果有人愿意看一下,它就在这里: https : //raiderforums.com/styles/corvus/template /rt_js/mootools-core.js

<div style="display: block;" class="gf-menu-toggle">
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
</div>

<div class="gf-menu-device-wrapper-sidemenu">
    <div class="gf-menu-device-container">
        <div class="gf-menu-device-container-wrapper">
            <ul class="gf-menu rt-desktop-menu l1  ">
                 <li class="items would follow">
             </ul>
         </div>
    </div>
</div>

You can use 您可以使用

display: none;

as it has been mentioned. 如前所述。 Though if you need to use calculations like height, etc before showing it, like contentHeight etc., this is not appropriate. 尽管如果需要在显示之前使用高度之类的计算,例如contentHeight等,这是不合适的。

In this case you may use 在这种情况下,您可以使用

opacity: 0.015;

or similar in CSS or even inline, and reset the opacity to 1 after hiding it via JavaScript. 或类似的CSS甚至内联,并通过JavaScript隐藏不透明度后将其重置为1。 This way it may not be that disturbing. 这样可能不会那么令人不安。

(Yes I know, inline CSS is ugly but blinking boxes are more that.) (是的,我知道,内联CSS 很难看,但闪烁的方框更是如此。)

Here's how I did it, thanks for the help guys. 这是我的操作方法,感谢帮助人员。 Changed the inline css to display:none, then this script got it working: 将内联css更改为display:none,然后此脚本使其起作用:

<script type="text/javascript"> 
$(document).ready( function(){ jQuery('.gf-menu').fadeIn(1000); }); 
</script>

See anything wrong with what I did? 看到我的工作有问题吗? It works, but perhaps I could have done it different? 它有效,但是也许我可以做得不同?

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

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