【问题标题】:Save div height in a cookie from jQuery resizable从 jQuery 可调整大小的 cookie 中保存 div 高度
【发布时间】:2009-07-22 15:53:22
【问题描述】:

我正在使用来自 interface.eyecon.ro/docs/resizable 的 jQuery resizable 作为我正在处理的页面上的菜单。我需要设置一个 cookie (plugins.jquery.com/project/Cookie) 来存储菜单 div 的高度,这样 div 就不会在每次重新加载页面时调整为原始 css 高度。

我一直在尝试修改 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');
        }
    });
});

这是我第一次使用stackoverflow,我希望我在这里看到的所有好的答案也都适用于这个问题:)

谢谢

【问题讨论】:

    标签: jquery interface cookies save resizable


    【解决方案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);
            }
        });
    });
    

    【讨论】:

    • 这正是我所需要的。非常感谢您快速正确的回答!
    猜你喜欢
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多