jQuery mobile page height

后端 未结 3 1944
时光取名叫无心
时光取名叫无心 2020-12-29 09:25

For the past day I have been trying to figure out how to change the min-height styling on a jQuery mobile page when viewing in mobile safari. I have tried, inline styles, ov

3条回答
  •  不思量自难忘°
    2020-12-29 10:12

    Old ticket but I have a solution which I prefer more. It specifically unbinds the resize event through some jQuery internals hacking. I don't like Jasper's solution because it depends on one event firing to block another, and events in theory should never know about each other / you should never depend on the order in which events fire.

    $(function() {
        // WARNING: Extremely hacky code ahead. jQuery mobile automatically
        // sets the current "page" height on page resize. We need to unbind the
        // resize function ONLY and reset all pages back to auto min-height.
        // This is specific to jquery 1.8
    
        // First reset all pages to normal
        $('[data-role="page"]').css('min-height', 'auto');
    
        // Is this the function we want to unbind?
        var check = function(func) {
            var f = func.toLocaleString ? func.toLocaleString() : func.toString();
            // func.name will catch unminified jquery mobile. otherwise see if
            // the function body contains two very suspect strings
            if(func.name === 'resetActivePageHeight' || (f.indexOf('padding-top') > -1 && f.indexOf('min-height'))) {
                return true;
            }
        };
    
        // First try to unbind the document pageshow event
        try {
            // This is a hack in jquery 1.8 to get events bound to a specific node
            var dHandlers = $._data(document).events.pageshow;
    
            for(x = 0; x < dHandlers.length; x++) {
                if(check(dHandlers[x].handler)) {
                    $(document).unbind('pageshow', dHandlers[x]);
                    break;
                }
            }
        } catch(e) {}
    
        // Then try to unbind the window handler
        try {
            var wHandlers = $._data(window).events.throttledresize;
    
            for(x = 0; x < wHandlers.length; x++) {
                if(check(wHandlers[x].handler)) {
                    $(window).unbind('throttledresize', wHandlers[x]);
                    break;
                }
            }
        } catch(e) {}
    });
    

提交回复
热议问题