2009-07-22 33 views
0

我使用jQuery的可調整大小從interface.eyecon.ro/docs/resizable爲我正在處理的頁面上的菜單。我需要設置一個cookie(plugins.jquery.com/project/Cookie)來存儲菜單div的高度,以便div在每次重新加載頁面時不會調整爲原始CSS高度。從jQuery保存div高度的cookie可調整大小

我一直在嘗試從http://www.shopdev.co.uk/blog/text-resizing-with-jquery/#comment-1044(我知道該代碼中存在一些錯誤,但我已經得到該示例工作)中的代碼,但現在我無法使其工作。

我的代碼看起來像這樣沒有cookie的事情:

$(document).ready(function() { 
    $('#resizeMe').Resizable({ 
     maxHeight: 600, 
     minHeight: 24, 
     handlers: { 
      s: '#resizeS' 
     }, 
     onResize: function(size) { 
      $('#content_two', this).css('height', size.height - 6 + 'px'); 
      $('#content').css('padding-top', size.height + 44 + 'px'); 
     } 
    }); 
}); 

這是我第一次在計算器,我希望所有的好答案,我在這裏也看到涉及到這個問題:)

感謝

回答

1

你或許可以嘗試這樣的事情:

$(document).ready(function() { 

    var cookieName = 'divHeight'; 

    //On document ready, if we find height from our cookie, 
    //we set the div to this height. 
    var height = $.cookie(cookieName); 
    if(height != null) 
     $('#resizeMe').css('height', height + 'px'); 


    $('#resizeMe').Resizable({ 
     maxHeight: 600, 
     minHeight: 24, 
     handlers: { 
       s: '#resizeS' 
     }, 
     onResize: function(size) { 
       $('#content_two', this).css('height', size.height - 6 + 'px'); 
       $('#content').css('padding-top', size.height + 44 + 'px'); 
       //I am assuming that onResize is triggered when user has finished resizing the DIV. If yes, you can store this div height in the cookie. 
       $.cookie(cookieName, size.height); 
     } 
    }); 
}); 
+0

這是EXAC tly我需要什麼。非常感謝您的快速和正確的答案! – 2009-07-22 18:36:28

相關問題