2013-01-14 12 views
1

我想在Facebook上做邊欄。那麼,不完全。我只想記住重新加載後或轉到其他頁面後的jQuery狀態。我不明白如何使用cookie插件。我在哪裏把它放在這個腳本?它是怎麼寫的?我下載了插件,它在html文件中,但我不知道如何通過jQuery執行它。如何使用jQuery Cookie插件讓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); 
    }); 
}); 

回答

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.cookie.js後才jquery.js

+0

@Cole請讓我知道這個解決方案是否有幫助。 – OMG

+0

其實我是以一種略有不同的方式做到這一點,但與你的方式非常相似。非常感謝喲:D。你現在也工作:D – Cole

相關問題