简体   繁体   中英

Customizing jQuery UI Slider height & width

When customizing the height/width of the jQuery UI Slider (and handle), the handle will now slide too far left (off of slider). Is there a recommended way of going about doing this?

Here's a fiddle to show you what I mean: http://jsfiddle.net/w7A4k/

I didn't see anything in the API Documentation for this, and I'm using a very basic setup:

$("#slider").slider({
    orientation: "horizontal",
    max: 100,
    min: 0
});

Try

fiddle demo

.ui-slider .ui-slider-handle {
    height: 15px;
    width: 5px;
    padding-left: 5px; //add this
}


To put the slider inside the bar add padding-left: 5px;

Unit size of JQuery UI Slider is in em . Therefore slider size is relative to its font size.

  • Change the font size of slider div to handle slider HEIGHT.
  • Change the container width of slider to handle slider WIDTH.
$(document).ready(function() {   
    function home_page_banner_height(selector) {   
        var wind_widht = $( window ).width();   
        var req_height = ( (banner_height / banner_width) * 100 );   
        //banner_height is height of item div of carousel and banner_width is width of item div of caousel 

        var calculate_height = (wind_widht / 100) * req_height;
        $('.v_center_con .v_center_inner').height(calculate_height);     
        $(selector).height(calculate_height);     
    }

    home_page_banner_height('.banner_con .item');     

    $(window).resize(function() {     
        home_page_banner_height('.banner_con .item');           
        //this function will make your slider responsive for all screen sizes
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM