Increment and decrease value with slider (slider)

Asked

Viewed 621 times

2

How can I create a flexible price list similar to this.

Is there any Javascript/jQuery plugin to implement these functions, that I can customize it?

  • 1

    For Jquery, the plugin is the slider() of Jqueryui: http://jqueryui.com/slider/

1 answer

4


jQuery has a plugin called "slider" makes the slider function, floating value.

To create your own table you can make a table simple HTML. What jQuery/Slider needs is a div so he can change and insert the button inside.

An example would be:

Demo: http://jsfiddle.net/y8Ye4/

$(".slider-cont").each(function () {
    var este = $(this);
    var minimo = parseFloat(este.closest('tr').find('.base_width').text(), 10);
    var maximo = este.data('max');
    var degraus = este.data('step');
    este.slider({
        range: "min",
        min: minimo,
        max: maximo,
        step: degraus,
        slide: function (event, ui) {
            mostrador.text(ui.value);
        }
    });
});

In this example above I inserted important information in HTML in "date" fields. A row of this table would look like this:

    <tr class="row">
        <td><span>RAM</span></td>
        <td class="slider"><div class="slider-cont" data-step="512" data-max="4096"></div></td>
        <td class="base"><span class="base_width">512 MB</span></td>
        <td class="total"><span class="total_width"><span class="total-value">512</span> MB</span></td>
    </tr>

If you take a look at plugin page can find configuration options. The ones I used were:

  • range: tell the slider which is of type "fixed minimum range"
  • min: starting value
  • max: maximum value
  • step: the increment value
  • slide: a function that updates the display every step of the slider

I suppose the code above is easy to understand. I leave an extra explanation for this line:

var minimo = parseFloat(este.closest('tr').find('.base_width').text(), 10);

Here I use the parseFloat(numero, base); that converts strings into floating numbers. This method is practical because it removes the text as well. And the number that I use inside I will get looking for the tr nearest (climbing up the DOM tree), and searching inside this tr the element with class .base_width and use text.

  • Hello @Sergio as always you helping me a lot! Only one thing remained: (It lacked the part of the price, as it is in the site I gave as example, where it is made the sum of the settings and it give the value)

  • 1

    @Alexandrelopes of course. I’m mobile but in two hours I’ll be back.

  • Queeeeeeeeeeeee Legaaaaaaaaaaaaaaaaaaaal!

  • Ex: each value of data-step="" vale 1 R$ and then he adds up the total of everything(CPD, RAM, HDD, LAN, etc...

  • 1

    @Alexandrelopes you have to have prices somewhere in order to generate the final value, I made an array in the example that can change. An example would be: http://jsfiddle.net/Cu96Z/ - more than this you have to adapt to your website and prices.

  • it couldn’t be like this? ex: data-step="1" data-max="10" and data-value="2" the data-value would be the price for each step.

  • 1

    @Alexandrelopes, yes it could, is a good idea. There are always several alternatives.

  • How do I do? I’m too Noob. :(

  • I thought it was so to change the value of each step: http://i.imgur.com/u8F2zBO.png

  • 1

    @Alexandrelopes http://jsfiddle.net/Cu96Z/1/ - the step value is the range with which the slider moves. In the case of RAM it is not possible to buy RAM if it is not in intervals/step of 512Mb for example

  • You could take a look at this question: http://answall.com/questions/25399/como-puxar-o-conte%C3%bado-via-ajax-de-um-site-that-has-a-hair%C3%a7garlic-com-menu-e-um ?

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.