jQuery Mobile panel width

后端 未结 7 1077
梦如初夏
梦如初夏 2020-12-30 09:53

In the new jQuery mobile there is a new panel option. I have implemented this and it works, but I would like to customize the width of the panel. The standard width is 272px

相关标签:
7条回答
  • 2020-12-30 10:33

    I didn't wanted to make modifications to the library css file so I tried above patches but none of them worked on jquery mobile 1.4.1

    I had to add few more styling to get it to work.

    Here is my modified css. (replace 10em and 15 em with your left and right size respectively)

    .ui-panel {
        width: 10em;
    }
    
    .ui-panel.ui-panel-position-right {
        width: 15em;
    }
    
    .ui-panel.ui-panel-closed {
        width: 0;
    }
    
    .ui-panel-animate.ui-panel-position-left.ui-panel-display-overlay, .ui-panel-animate.ui-panel-position-left.ui-panel-display-push {
        -webkit-transform: translate3d(-10em, 0, 0);
        -moz-transform: translate3d(-10em, 0, 0);
        transform: translate3d(-10em, 0, 0)
    }
    
    .ui-panel-animate.ui-panel-position-right.ui-panel-display-overlay, .ui-panel-animate.ui-panel-position-right.ui-panel-display-push {
        -webkit-transform: translate3d(15em, 0, 0);
        -moz-transform: translate3d(15em, 0, 0);
        transform: translate3d(15em, 0, 0)
    }
    
    .ui-panel-animate.ui-panel-content-fixed-toolbar-position-left.ui-panel-content-fixed-toolbar-open.ui-panel-content-fixed-toolbar-display-reveal, .ui-panel-animate.ui-panel-content-fixed-toolbar-position-left.ui-panel-content-fixed-toolbar-open.ui-panel-content-fixed-toolbar-display-push, .ui-panel-animate.ui-panel-content-wrap-position-left.ui-panel-content-wrap-open.ui-panel-content-wrap-display-reveal, .ui-panel-animate.ui-panel-content-wrap-position-left.ui-panel-content-wrap-open.ui-panel-content-wrap-display-push {
        -webkit-transform: translate3d(10em, 0, 0);
        -moz-transform: translate3d(10em, 0, 0);
        transform: translate3d(10em, 0, 0)
    }
    
    .ui-panel-animate.ui-panel-page-content-position-left{
        -webkit-transform: translate3d(10em, 0, 0);
        -moz-transform: translate3d(10em, 0, 0);
        transform: translate3d(10em, 0, 0);
    }
    
    .ui-panel-animate.ui-panel-content-fixed-toolbar-position-right.ui-panel-content-fixed-toolbar-open.ui-panel-content-fixed-toolbar-display-reveal, .ui-panel-animate.ui-panel-content-fixed-toolbar-position-right.ui-panel-content-fixed-toolbar-open.ui-panel-content-fixed-toolbar-display-push, .ui-panel-animate.ui-panel-content-wrap-position-right.ui-panel-content-wrap-open.ui-panel-content-wrap-display-reveal, .ui-panel-animate.ui-panel-content-wrap-position-right.ui-panel-content-wrap-open.ui-panel-content-wrap-display-push {
        -webkit-transform: translate3d(-15em, 0, 0);
        -moz-transform: translate3d(-15em, 0, 0);
        transform: translate3d(-15em, 0, 0)
    }
    
    0 讨论(0)
  • 2020-12-30 10:34

    you need to put the following css (left panel)

    .ui-panel{
        width: 150px!important;
    }
    
    .ui-panel-animate.ui-panel-page-content-position-left {
    
        transform: translate3d(150px,0,0) !important;
    }
    
    0 讨论(0)
  • 2020-12-30 10:35

    They show how to change the panel width in this demo: http://jquerymobile.com/demos/1.3.0/docs/examples/panels/panel-styling.html

    0 讨论(0)
  • 2020-12-30 10:45

    If you don't want to globally edit the size, add this to your custom css adding IDs where necessary, changing 23em to your desired width:

    Note: This is only for the left side.

    .ui-panel {
        width: 23em;
    }
    .ui-panel-position-left {
        left: -23em;
    }
    /* positioning: content wrap, fixed toolbars and dismiss */
    /* panel left open */
    .ui-panel-content-fixed-toolbar-position-left.ui-panel-content-fixed-toolbar-open,
    .ui-panel-content-wrap-position-left.ui-panel-content-wrap-open,
    .ui-panel-dismiss-position-left.ui-panel-dismiss-open {
        left: 23em;
        right: -23em;
    }
    /* animated: panel left open (for reveal and push) */
    .ui-panel-animate.ui-panel-content-fixed-toolbar-position-left.ui-panel-content-fixed-toolbar-open.ui-panel-content-fixed-toolbar-display-reveal,
    .ui-panel-animate.ui-panel-content-fixed-toolbar-position-left.ui-panel-content-fixed-toolbar-open.ui-panel-content-fixed-toolbar-display-push,
    .ui-panel-animate.ui-panel-content-wrap-position-left.ui-panel-content-wrap-open.ui-panel-content-wrap-display-reveal,
    .ui-panel-animate.ui-panel-content-wrap-position-left.ui-panel-content-wrap-open.ui-panel-content-wrap-display-push {
        -webkit-transform: translate3d(23em,0,0);
        -moz-transform: translate3d(23em,0,0);
        transform: translate3d(23em,0,0);
    }
    
    0 讨论(0)
  • 2020-12-30 10:48

    I had same issue myself and followed tylerl's advice to replace 17em with the width I needed. Which worked well, except for the fact that I was using google cdn to load css, so I could not change it directly and in general I am not a big fan of changing library code.

    So playing around with it a little I came up with this code for redefining default jquery mobile's css https://gist.github.com/geekdevs/5433246

    You can configure width for left and right sidebars separately. This is LESS code, but simply replacing @left-sidebar-width and @right-sidebar-width with the width you need will make it work for plain CSS as well.

    0 讨论(0)
  • 2020-12-30 10:51

    I think you've made a typo. Try

    .ui-panel { width: 150px; }
    

    or if you're issuing that inline, perhaps

    <panel style="width: 150px;">
    

    Of course, new as I am to jquery, I could be wrong.

    0 讨论(0)
提交回复
热议问题