【问题标题】:Page background image moves and stretch with collapsible set in jQuery mobile 1.4.0使用 jQuery mobile 1.4.0 中的可折叠集移动和拉伸页面背景图像
【发布时间】:2014-02-27 22:36:43
【问题描述】:

我在我的 jQuery 移动应用程序中有一个 Collapsible 集,问题是当我在展开时为页面添加背景图像时,关闭可折叠的背景图像会拉伸并随着可折叠物移动,当我从我的CSS:

background-repeat: no-repeat; 
background-size: 100% 100%;

这个问题已经解决了,但这导致了另一个大问题,即当我展开可折叠然后关闭它时,背景会缩小“随着可折叠而向上移动”并且此可折叠下方的页面部分变得没有背景“透明“这发生在移动设备上比 jsFiddle 更多,这是我的 jsfiddle

请帮助我如何解决这个问题,以便在不影响页面背景图像的情况下展开和关闭折叠项?

【问题讨论】:

    标签: jquery-mobile background-image jquery-mobile-collapsible


    【解决方案1】:

    您可以使用 javascript 将内容调整为设备大小:http://jqmtricks.wordpress.com/2014/02/06/content-div-height-fill-page-height/

    更新FIDDLE

    $(document).on("pageshow", function(){
        SizeContent();
    });
    $(window).on("resize orientationchange", function(){
        SizeContent();
    });
    
    function SizeContent(){
        var screen = $.mobile.getScreenHeight();
        //if you have a page header
        var header = $(".ui-header").hasClass("ui-header-fixed") ? $(".ui-header").outerHeight() - 1 : $(".ui-header").outerHeight();
        //if you have a page footer
        var footer = $(".ui-footer").hasClass("ui-footer-fixed") ? $(".ui-footer").outerHeight() - 1 : $(".ui-footer").outerHeight();
    
        /* content div has padding of 1em = 16px (32px top+bottom). This step
       can be skipped by subtracting 32px from content var directly. */
        var contentCurrent = $(".ui-content").outerHeight() - $(".ui-content").height();
    
        var content = screen - header - footer - contentCurrent;
    
        $(".ui-content").height(content);   
    }
    

    【讨论】:

    • @ezankerThanks 非常感谢这解决了问题,但出现了一个奇怪的问题,有时我并不总是需要多次单击第三个可折叠“Governorate3”才能展开,如果还有其他问题collapsible 已展开,这第三个 collapsible 没有关闭!
    • 这种情况只发生在可折叠的 #3 中!
    • 我无法重现该行为...如果回答了操作,请接受。
    • @ezankerIts 发生在手机上,有时并非总是如此,我已经查看了代码,但它仍然发生 :(,当然我会接受并 +1
    • 谢谢。我看不出代码有任何明显错误。
    猜你喜欢
    • 1970-01-01
    • 2013-12-06
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 1970-01-01
    • 2017-10-12
    相关资源
    最近更新 更多