Jquery slider plugin that supports “Multiple Ranged Handles” [closed]

女生的网名这么多〃 提交于 2019-12-03 06:02:06

I've just released Elessar to fill this exact niche. colResizable is fine, but it's not really the right tool for the job.

Here's how I did it.

myarr = [ 65, 80, 90 ];
$(function() {
    $( "#slider-range" ).slider({
        min: 0,
        max: 100,
        values: myarr,
        slide: function( event, ui ) {
            if ( ui.values[0] >= ui.values[1] ) {
                return false;
            }
            if ( ui.values[1] >= ui.values[2] ) {
                return false;
            }
            $(this).find(".range0").css({ "width": ui.values[0] + "%" });
            $(this).find(".range1").css({ "left": ui.values[0] + "%", "width": (ui.values[1]-ui.values[0])  + "%" }) ;
            $(this).find(".range2").css({ "left": ui.values[1] + "%", "width": (ui.values[2]-ui.values[1]) + "%" }) ;
            $(this).find(".range3").css({ "left": ui.values[2] + "%", "width": (100-ui.values[2]) + "%" }) ;
        },
        create: function(event, ui) {
                $(this).append('<div class="ui-slider-range ui-widget-header range0" style="left: 0%; width: ' + myarr[0] + '%; background: none repeat scroll 0% 0% #CF1920;"></div>');
                $(this).append('<div class="ui-slider-range ui-widget-header range1" style="left: ' + myarr[0] + '%; width: ' + (100-myarr[1]) + '%; background: none repeat scroll 0% 0% #FFE900;"></div>');
                $(this).append('<div class="ui-slider-range ui-widget-header range2" style="left: ' + myarr[1] + '%; width: ' + (100-myarr[2]) + '%; background: none repeat scroll 0% 0% #26CF2D;"></div>');
                $(this).append('<div class="ui-slider-range ui-widget-header range3" style="left: ' + myarr[2] + '%; width: ' + (100-myarr[2]) + '%; background: none repeat scroll 0% 0% #00BCFF;"></div>');
        }
    });
});

Im sure it can be optimized more, but this should give you the general idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!