1

私は新しいメニューコードをテストしていますが、問題の1つは、すべてが読み込まれ、すべての読み込みが完了すると所定の位置にジャンプすることです。

だから私がしようとしているのは、ドキュメントの準備ができるまでそれを非表示にしてから表示することです

だから、それを隠すためのCSS:

#mega-menu-1 {
font: normal 13px Arial, sans-serif; 
list-style: none; 
position: relative; 
padding: 0; 
margin: 0;
margin-top:13px;
display: none;
}

次に、ページの最後でjqueryを呼び出してメニューをロードし、表示をブロックに変更しますが、メニューが表示されません

これが私が試しているjqueryです:

<script type="text/javascript">
    $(document).ready(function($){
        $('#mega-menu-1').dcMegaMenu({
            rowItems: '2',
            event: 'click',
            fullWidth: false
        });
        $('#mega-menu-1').css('display') == 'block';
    });
</script>

これを行う正しい方法は何ですか?

4

5 に答える 5

7

If you are trying to set the display property then you have wrong syntax for jQuery function css(), you need css( propertyName , value) to set property value.

Change

$('#mega-menu-1').css('display') == 'block';

To

$('#mega-menu-1').css('display', 'block') ;

OR You can also call jQuery show() method that will do the same.

$('#mega-menu-1').show();
于 2012-12-28T08:57:35.613 に答える
1

You should use :

<script type="text/javascript">
    $(document).ready(function($){
        $('#mega-menu-1').dcMegaMenu({
            rowItems: '2',
            event: 'click',
            fullWidth: false
        });
        $('#mega-menu-1').show();
    });
</script>

reference website

于 2012-12-28T09:03:21.467 に答える
1

I think the problem is the "dcMegaMenu" plugin just loaded from extern source (a JS-file). Try this, it helped me once in another project:

<script type="text/javascript">
    $(document).ready(function($){
        $('#mega-menu-1').dcMegaMenu({
            rowItems: '2',
            event: 'click',
            fullWidth: false
        });
        $(document).find('#mega-menu-1').css({'display' : 'block'});
    });
</script>
于 2012-12-28T09:13:47.053 に答える
0

I made you a jsFiddle test page where your menu get displayed.

A minor update in the display value change, but also I have commented out your .dcMegaMenu statement (cause you don't give any information about it). And if you still have the issue is probably because it fails on this one.

$('#mega-menu-1').css('display', 'block');

Hope this helps.

于 2012-12-28T09:09:43.007 に答える
-1

It is jQuery Syntax, not JavaScript

Replace:

$('#mega-menu-1').css('display') == 'block';

With:

$('#mega-menu-1').css('display', 'block');

And if you want to use getters and setters:

Set: $('#mega-menu-1').css('display', 'block');

Get: $('#mega-menu-1').css('display');

Compare: $('#mega-menu-1').css('display') == "block"

于 2012-12-28T08:59:25.597 に答える