简体   繁体   English

如何在jqueryUI滑块中添加PIPS

[英]how to add PIPS in jqueryUI Slider

I need to add 6 pips in JqueryUI slider. 我需要在JqueryUI滑块中添加6个点。 The PIPS wopuld range from 2000, 2010, 2020, 2030, 2040, 2050. I'm unable to get the understand functionality of adding these pips. PIPS的范围为2000、2010、2020、2030、2040、2050。我无法理解添加这些点的功能。 Also, currently the slider has been coded to work on step sliding effect. 另外,目前已对滑块进行编码,以实现逐步滑动效果。 Here is the code I'm using: 这是我正在使用的代码:

    <div id="slider"></div>
    <script>
    $(function() {

var extensionMethods = {

            pips: function( settings ) {

                options = {

                    first:  "number",   // "pip" , false
                    last:   "number",   // "pip" , false
                    rest:   "pip"       // "number" , false

                };

                $.extend( options, settings );

                // get rid of all pips that might already exist.
                this.element.addClass('ui-slider-pips').find( '.ui-slider-pip' ).remove();

                // we need teh amount of pips to create.
                var pips = this.options.max - this.options.min;                 

                    // for every stop in the slider, we create a pip.
                    for( i=0; i<=pips; i++ ) {

                        // hold a span element for the pip
                        var s = $('<span class="ui-slider-pip"><span class="ui-slider-line"></span><span class="ui-slider-number">'+i+'</span></span>');

                        // add a class so css can handle the display
                        // we'll hide numbers by default in CSS, and show them if set.
                        // we'll also use CSS to hide the pip altogether.
                        if( 0 == i ) {
                            s.addClass('ui-slider-pip-first');
                            if( "number" == options.first ) { s.addClass('ui-slider-pip-number'); }
                            if( false == options.first ) { s.addClass('ui-slider-pip-hide'); }
                        } else if ( pips == i ) {
                            s.addClass('ui-slider-pip-last');
                            if( "number" == options.last ) { s.addClass('ui-slider-pip-number'); }
                            if( false == options.last ) { s.addClass('ui-slider-pip-hide'); }
                        } else {
                            if( "number" == options.rest ) { s.addClass('ui-slider-pip-number'); }
                            if( false == options.rest ) { s.addClass('ui-slider-pip-hide'); }
                        }


                        // if it's a horizontal slider we'll set the left offset,
                        // and the top if it's vertical.
                        if( this.options.orientation == "horizontal" ) 
                            s.css({ left: '' + (100/pips)*i + '%'  });
                        else
                            s.css({ top: '' + (100/pips)*i + '%'  });


                        // append the span to the slider.
                        this.element.append( s );

                    }

            }


        };

        $.extend(true, $['ui']['slider'].prototype, extensionMethods);


        $("#slider").slider({
            min: 0,
            max: 600,
            step: 100,


            // on slide adjust width of all rects
            slide: function(event, ui) {

                svg.selectAll("rect")
                        .attr("width", function (d) {

Well JQuery-UI slider doesn't have pip's by default. 好吧,JQuery-UI滑块默认情况下没有pip。 To get pip's refer to the link below 要获得点子,请参考以下链接

https://github.com/simeydotme/jQuery-ui-Slider-Pips https://github.com/simeydotme/jQuery-ui-Slider-Pips

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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