2012-11-25 72 views
-1

如何在用戶轉到其他頁面或刷新頁面後隱藏div?我在頁腳下面的代碼,以便它加載的每個頁面上:刷新/更改頁面後保持項目關閉

$(document).ready(function() { 
$('#clickmebottom').click(function() { 
     $('#bottomfixtab').animate({ 
      height: 'toggle' 
      }, 350 
    ); 
}); 
}); 

#clickmebottom是一個X按鈕 - 點擊上 - 隱藏#bottomfixtab格(小橫幅固定在屏幕底部)

感謝您的幫助

+4

看看餅乾:https://github.com/carhartl/jquery-cookie –

回答

1

您可以使用jQuery插件如jquery-cookie來簡化cookie訪問。所以,你的代碼將變得像這樣保存div的切換設置:

// pseudo-code, you'll want to check the actual syntax 
$(document).ready(function() { 

    // see if the cookie is set, if it is, hide the div 
    if ($.cookie('toggledDiv') { 
    $('#bottomfixtab').hide(); 
    } 
    $('#clickmebottom').click(function() { 
    $.cookie('toggledDiv'); 
    $('#bottomfixtab').animate({ 
     height: 'toggle' 
    }, 350); 
    }); 
}); 

這將可能使隨後的股利閃光燈隱藏,所以如果你想避免的那一剎那,默認設置爲顯示:沒有,那麼如果該cookie是設定,顯示DIV:

// again, pseduo-code 
if (!$.cookie('toggledDiv')) { 
    $('#bottomfixtab').show() 
}