• Resolved timobock

    (@timobock)


    Hi,

    is it possible to make the slider use a logarithmic scale? We have a wide range to cover. On the lower end of the scale it needs to work in smaller increments while on the upper end the increments can be larger. If the slider used a logarithm scale, the experience for the user would be improved. Is that possible?

    Thanks

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @timobock

    To create a logarithmic slider, you should customize the form’s code.

    For example, assuming you want to apply this behavior to the slider field: fieldname16, insert an “HTML Content” field in the form with the following piece of code as its content:

    
    <script>
    fbuilderjQuery(document).one('showHideDepEvent', function () {
        var $ = jQuery,
            f = fbuilderjQuery.fbuilder.forms['_1'].getItem('fieldname16');
        jQuery('#'+f.name+'_slider').slider('option', 'slide', null);		
        jQuery('#'+f.name+'_slider').slider('option', 'stop', null);		
        jQuery('#'+f.name+'_slider').on('slide stop', function (event, ui) {
            var v = ROUND(expon(MAX(jQuery(this).slider('option', 'min'),1),
                jQuery(this).slider('option', 'max'), ui.value));
            $( '#'+f.name ).val( v );
            $( '#'+f.name+'_caption' ).html(
                f.caption
                .replace( /\{\s*0\s*\}/, f._setThousandsSeparator( v ) )
            );
            $( '#'+f.name ).change();
        });
    });
    
    function expon(min, max, val) {
        var minv = Math.log(min);
        var maxv = Math.log(max);
        var scale = (maxv - minv) / (max - min);
        return Math.exp(minv + scale * (val - min));
    }
    </script>
    

    and that’s all.
    Best regards.

    • This reply was modified 4 years, 8 months ago by codepeople.
    Thread Starter timobock

    (@timobock)

    Wow, this is great. The only issue now is that the increments are no longer multiples of 10.000. The original setting was that each step is 10.000 units. Would it be possible to round numbers up or down so that they are multiples of 10.000?

    Plugin Author codepeople

    (@codepeople)

    Hello @timobock

    You can replace, in the previous block of code, the line:

    
    var v = ROUND(expon(MAX(jQuery(this).slider('option', 'min'),1),            jQuery(this).slider('option', 'max'), ui.value));
    

    as follows:

    
    var v = ROUND(expon(MAX(jQuery(this).slider('option', 'min'),1),            jQuery(this).slider('option', 'max'), ui.value), 10000);
    

    I’m sorry, the support service does not cover the implementation of the users’ projects. If you need additional support customizing your controls, you can contact me through my private website: Customization

    Best regards.

    Thread Starter timobock

    (@timobock)

    amazing! Thansk

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Logarithmic slider’ is closed to new replies.