1

Facebookのようにサイドバーを作ろうとしています。まあ、完全ではありません。リロード後または別のページに移動した後のjQueryの状態を覚えておきたいだけです。Cookieプラグインの使い方がわかりません。このスクリプトのどこに配置しますか?そしてそれはどのように書かれていますか?プラグインをダウンロードしました。これはhtmlファイル内にありますが、jQueryを介してプラグインを実行する方法がわかりません。

$(document).ready(function(){
    $("#arrow").bind('click', function(){
        $('#wrappernav').fadeOut("fast");
        $('#sidebar').fadeOut("fast");
        $('#wrappernavbg').fadeOut("fast");
        $('#naviclosed').fadeIn("fast");
        $(window).unbind('resize');
     //I want jQuery to remember this state after refresh.

    });
    $('#naviclosed').bind('click', function () {
        $('#wrappernav').fadeIn("fast");
        $('#sidebar').fadeIn("fast");
        $('#wrappernavbg').fadeIn("fast");
        $('#naviclosed').fadeOut("fast");
        $(window).bind('resize', ScreenSize);
    });
});
4

1 に答える 1

1

コードにわずかな変更を加えました:

<script>
function clickArrow()
{
    $('#wrappernav').fadeOut("fast");
    $('#sidebar').fadeOut("fast");
    $('#wrappernavbg').fadeOut("fast");
    $('#naviclosed').fadeIn("fast");
    $(window).unbind('resize');
}

$(document).ready(function(){

    //Do the animations automatically IF the cookie value was SET.
    var arrowClicked = parseInt($.cookies.get('arrowClicked')); 
    if (arrowClicked > 0) {
        clickArrow(); 
    }

    $("#arrow").bind('click', function(){

     //Perform actions
     clickArrow();

     //I want jQuery to remember this state after refresh.
     $.cookies.set('arrowClicked', 1);
    });

    $('#naviclosed').bind('click', function () {
        $('#wrappernav').fadeIn("fast");
        $('#sidebar').fadeIn("fast");
        $('#wrappernavbg').fadeIn("fast");
        $('#naviclosed').fadeOut("fast");
        $(window).bind('resize', ScreenSize);
    });
});

Cookie プラグインの詳細については、次のリンクにアクセスしてください: http://code.google.com/p/cookies/

また、jquery.js の後にのみ jquery.cookie.js を含めてください。

于 2013-01-14T09:55:42.650 に答える