爱游戏官网 TouchSpin Component Demo

Github project page Download

A Bootstrap number input component designed for mobile and touch screens, supporting mouse wheel and arrow key operations for a smooth user experience.

Core Feature Showcase

<input id="demo0"
       type="text"
       value="55"
       name="demo0"
       data-bts-min="0"
       data-bts-max="100"
       data-bts-init-val=""
       data-bts-step="1"
       data-bts-decimal="0"
       data-bts-step-interval="100"
       data-bts-force-step-divisibility="round"
       data-bts-step-interval-delay="500"
       data-bts-prefix=""
       data-bts-postfix=""
       data-bts-prefix-extra-class=""
       data-bts-postfix-extra-class=""
       data-bts-booster="true"
       data-bts-boostat="10"
       data-bts-max-boosted-step="false"
       data-bts-mousewheel="true"
       data-bts-button-down-class="btn btn-default"
       data-bts-button-up-class="btn btn-default"
        />
<script>
    $("input[name='demo0']").TouchSpin({
    });
</script>
<input id="demo_vertical" type="text" value="" name="demo_vertical">
<script>
    $("input[name='demo_vertical']").TouchSpin({
      verticalbuttons: true
    });
</script>
<input id="demo_vertical2" type="text" value="" name="demo_vertical2">
<script>
    $("input[name='demo_vertical2']").TouchSpin({
      verticalbuttons: true,
      verticalupclass: 'glyphicon glyphicon-plus',
      verticaldownclass: 'glyphicon glyphicon-minus'
    });
</script>
<input id="demo1" type="text" value="55" name="demo1">
<script>
    $("input[name='demo1']").TouchSpin({
        min: 0,
        max: 100,
        step: 0.1,
        decimals: 2,
        boostat: 5,
        maxboostedstep: 10,
        postfix: '%'
    });
</script>
<form class="form-horizontal" role="form">
    <div class="form-group">
        <label for="demo2" class="col-md-5 control-label">Example:</label> <input id="demo2" type="text" value="0" name="demo2" class="col-md-7 form-control">
    </div>
</form>

<script>
    $("input[name='demo2']").TouchSpin({
        min: -1000000000,
        max: 1000000000,
        stepinterval: 50,
        maxboostedstep: 10000000,
        prefix: '$'
    });
</script>
<input id="demo3" type="text" value="" name="demo3">
<script>
    $("input[name='demo3']").TouchSpin();
</script>

The `initval` configuration option takes effect only when the input box does not have a `value` attribute, and is used to set the initial value.

<input id="demo3_21" type="text" value="" name="demo3_21">
<script>
    $("input[name='demo3_21']").TouchSpin({
        initval: 40
    });
</script>
<input id="demo3_22" type="text" value="33" name="demo3_22">
<script>
    $("input[name='demo3_22']").TouchSpin({
        initval: 40
    });
</script>

The overall controller size can be adjusted by adding `.input-sm` or `.input-lg` classes to the input box, or by placing it within a correspondingly sized `.input-group`.

<input id="demo4" type="text" value="" name="demo4" class="input-sm">
<script>
    $("input[name='demo4']").TouchSpin({
        postfix: "a button",
        postfix_extraclass: "btn btn-default"
    });
</script>
<div class="input-group input-group-lg">
    <input id="demo4_2" type="text" value="" name="demo4_2" class="form-control input-lg">
</div>
<script>
    $("input[name='demo4_2']").TouchSpin({
        postfix: "a button",
        postfix_extraclass: "btn btn-default"
    });
</script>
<div class="input-group">
    <input id="demo5" type="text" class="form-control" name="demo5" value="50">
    <div class="input-group-btn">
        <button type="button" class="btn btn-default">Action</button>
        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
        </button>
        <ul class="dropdown-menu pull-right" role="menu">
            <li><a href="#">Action</a></li>
            <li><a href="#">Another action</a></li>
            <li><a href="#">Something else here</a></li>
            <li class="divider"></li>
            <li><a href="#">Separated link</a></li>
        </ul>
    </div>
</div>
<script>
    $("input[name='demo5']").TouchSpin({
        prefix: "pre",
        postfix: "post"
    });
</script>
$("input[name='demo6']").TouchSpin({
    buttondown_class: "btn btn-link",
    buttonup_class: "btn btn-link"
});
$("input[name='demo7']").TouchSpin({
    replacementval: 10
});

Interactive Feature Demo

 

Configuration Options Explained

Option Default Value Description
initval "" Applied when the input box does not have a `value` attribute. An empty string indicates an empty initial value.
replacementval "" Applied when the user leaves it blank or enters non-numeric characters. An empty string means the value will not be replaced.
min 0 Minimum value.
max 100 Maximum value.
step 1 Step increment/decrement.
forcestepdivisibility 'round' Method to force values to be divisible by the step.
decimals 0 Decimal places.
stepinterval 100 Refresh interval for the spinner (milliseconds).
stepintervaldelay 500 Delay before the spinner starts rotating (milliseconds).
verticalbuttons false Enable traditional up and down buttons.
verticalupclass 'glyphicon glyphicon-chevron-up' Class for the down button when vertical button mode is enabled.
verticaldownclass 'glyphicon glyphicon-chevron-down' Class for the up button when vertical button mode is enabled.
prefix "" Prefix text for the input box.
postfix "" Suffix text for the input box.
prefix_extraclass "" Additional class for the prefix.
postfix_extraclass "" Additional class for the suffix.
booster true When enabled, holding down the button will continuously increase the spinner speed.
boostat 10 Number of steps per acceleration.
maxboostedstep false Maximum number of steps during acceleration.
mousewheel true Enable mouse wheel to change input value.
buttondown_class 'btn btn-default' Class for the down button.
buttonup_class 'btn btn-default' Class for the up button.
buttondown_txt '-' Content inside the down button.
buttonup_txt '+' Content inside the up button.

Event Trigger Explanation

Event Trigger

The component triggers the following events, which you can listen to and execute custom logic:

Event Description
change Triggered when the value is changed by buttons (does not trigger when the spinner reaches the limit set by `max` or `min`).
touchspin.on.startspin Triggered when the spinner starts rotating up or down.
touchspin.on.startupspin Triggered when the spinner starts rotating upwards.
touchspin.on.startdownspin Triggered when the spinner starts rotating downwards.
touchspin.on.stopspin Triggered when the spinner stops rotating.
touchspin.on.stopupspin Triggered when the spinner stops rotating upwards.
touchspin.on.stopdownspin Triggered when the spinner stops rotating downwards.
touchspin.on.min Triggered when the value reaches the preset maximum.
touchspin.on.max When the value reaches the preset minimum, the system will automatically perform predefined operations.

Callable Methods

You can trigger component events or update its settings using the following JavaScript methods:

Example Usage: $("input").trigger("touchspin.uponce"); $("input").trigger("touchspin.updatesettings", {max: 1000});

Event Description
touchspin.updatesettings `updatesettings`: Update any settings of an initialized TouchSpin instance.
touchspin.uponce Increase the value by one step.
touchspin.downonce Decrease the value by one step.
touchspin.startupspin Start the spinner upwards.
touchspin.startdownspin Start the spinner downwards.
touchspin.stopspin Stop the spinner.

Get & Support

Get it on GitHub. Issues and suggestions are welcome via the GitHub issue tracker, or contact us through official channels!

爱游戏官网 Technology Co., Ltd.Excellence in every detailPhone:+86 177 9824 1616Email:[email protected]824 Zhangjiang Road, Pudong New Area, Shanghai