【问题标题】:jQuery UI slider: Overlaying the range imagejQuery UI 滑块:覆盖范围图像
【发布时间】:2012-04-05 11:13:31
【问题描述】:

我正在构建一个垂直范围滑块:

这会很棒。

使用 jQuery UI 1.8 实现,不过,我只走了这么远:

我已将滑块包装在一个容器中,该容器具有 padding-toppadding-bottom 以保持滑块的范围元素就位。

没有容器,范围会与背景重叠:

有什么好的解决办法吗?

这里有一些代码,如果需要的话:

少代码:

    /*
     * Center the slider by wrapping it in a container
     */
    .slider-container {
        text-align: center;

        /*
         * Another container that holds the actual background of the slider,
         * with padding to make sure the handle doesn't go outside of the background.
         */
        .slider-bg {
            background: transparent url('/static/images/slider_bg.png') 0% 0%;
            height: 235px;
            width: 28px;
            padding-top: 20px;
            padding-bottom: 7px;
            margin: 0 auto;

            /*
             * The actual element holding the slide handler
             */
            .ui-slider {
                height: 234px;
                width: 28px;
                background: none;

                // Overrides
                .border-radius(0 0 0 0);
                border: 0;

                .ui-slider-handle {
                    width: 28px;
                    height: 29px;

                    background: transparent url('/static/images/slider_handle.png') 0% 0%;

                    // Overrides
                    left: 0;
                    .border-radius(0 0 0 0);
                    border: 0;
                }

                .ui-slider-range {
                    width: 28px;
                    background: transparent url('/static/images/slider_range.png') 0% 0%;
                    padding-bottom: 13px;
                }
            }
        }
    }

JS:

$('div.slider').slider({
    orientation: 'vertical',
    animate: 'true',
    range: 'min',
    slide: function (event, ui) {
    }
});

【问题讨论】:

  • 您不想向我们展示您的代码吗?
  • 不确定是否有必要。已更新。
  • 啊废话,我链接到的图像的 URL 错误。我现在已经上传了它们。

标签: jquery css jquery-ui jquery-ui-slider


【解决方案1】:

这样做:

/* Corner radius */
.ui-corner-all, .ui-corner-top, .ui-corner-left, .ui-corner-tl { -moz-border-radius-topleft: 14px; -webkit-border-top-left-radius: 14px; -khtml-border-top-left-radius: 14px; border-top-left-radius: 14px; }
.ui-corner-all, .ui-corner-top, .ui-corner-right, .ui-corner-tr { -moz-border-radius-topright: 14px; -webkit-border-top-right-radius: 14px; -khtml-border-top-right-radius: 14px; border-top-right-radius: 14px; }
.ui-corner-all, .ui-corner-bottom, .ui-corner-left, .ui-corner-bl { -moz-border-radius-bottomleft: 14px; -webkit-border-bottom-left-radius: 14px; -khtml-border-bottom-left-radius: 14px; border-bottom-left-radius: 14px; }
.ui-corner-all, .ui-corner-bottom, .ui-corner-right, .ui-corner-br { -moz-border-radius-bottomright: 14px; -webkit-border-bottom-right-radius: 14px; -khtml-border-bottom-right-radius: 14px; border-bottom-right-radius: 14px; }

和 UI 小部件标题:

.ui-widget-header
{
    border: 1px solid #dddddd;
    background: #33CCFF url(images/ui-bg_highlight-soft_50_dddddd_1x100.png) repeat-x 50% 50%;
    color: #444444;
    font-weight: bold;
    -moz-border-radius: 14px;
    border-radius: 14px;
}

小部件内容:

.ui-widget-content {background: #ffffff url(images/ui-bg_flat_75_ffffff_40x100.png) 50% 50% repeat-x; color: #444444; }

这是给你的demo

【讨论】:

  • 感谢您的详尽回答!不幸的是,依靠边界半径在 IE 中不起作用。我总是可以使用 CSS3 PIE,但我认为我最终不会得到与使用图像相同的结果。我会考虑的,谢谢。希望有一个跨浏览器的解决方案!
  • 另外,你知道你不必像在演示中那样重复左上半径和右上半径等吗? border-radius: 14px 就足够了(加上所有供应商前缀)。
【解决方案2】:
NameError: .border-radius is undefined on line 27, column 17:

26                 
27                 .border-radius(0 0 0 0);
28                 border: 0;

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2021-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    相关资源
    最近更新 更多