AlloyTouch infinite loop select plug-in

Source: Internet
Author: User
When there is a lot of scrolling content, such as setting seconds in the alarm, there are a total of 60 items. It is very painful for users to roll back from 59ms to 01ms. Therefore, when there are too many items in the list, we hope to have an infinite loop of scrolling. Ms and Ms are seamlessly linked. As shown in: Preface

When there is a lot of scrolling content, such as setting seconds in the alarm, there are a total of 60 items. It is very painful for the user to roll back from 59ms to 01ms, so:
When there are too many items in the list, we hope to have an infinite loop of scrolling. Ms and Ms are seamlessly linked. As shown in:

Var I = 0, options = []; for (; I <60; I ++) {options. push ({value: I, text: I <10? "0" + I + "ms": I + "ms"});} var iselect = new AlloyTouch. select ({options: options, selectedIndex: 11, change: function (item, index) {}, complete: function (item, index) {document. body. insertAdjacentHTML ("beforeEnd ","
Select "+ index +"
Value: "+ item. value +"
Text: "+ item. text) ;}}) iselect. show ();
  • Options is a set of all items. The above 60 simulated items represent the corresponding ms

  • SelectedIndex is the index of the initial selected item.

  • Change is the callback of change.

  • Complete is the callback of the click Finish button.

Core Principles

Before looking at the principle, let's look at the attribute changes in the dom.

new AlloyTouch({    touch: container,    target: { y: -1 * preSelectedIndex * step },    property: "y",    vertical: true,    step: step,    change: function (value) {        correction(value);    },    touchStart: function (evt, value) { },    touchMove: function (evt, value) { },    touchEnd: function (evt, value) { },    tap: function (evt, value) { },    pressMove: function (evt, value) { },    animationEnd: function (value) { }})function correction(value) {    value %= scrollerHeight;    if (Math.abs(value) > scrollerHeight-90) {        if (value > 0) {            value -= scrollerHeight;        } else {            value += scrollerHeight;        }    }    scroll.translateY = value - scrollerHeight;}

We can see that the min and max parameters do not exist when the AlloyTouch instance is initialized, because no rebound is required.
Use correction to produce the effect of a beat cycle. (Note: although the value will skip a cycle, the dom rendering performance cannot be seen)
Target is an object literal that contains the y attribute,
Scroll is a rolling object that has been blended with the relevant properties of transfrom. Therefore, you can directly set the displacement in the vertical direction through scroll. translateY.

Summary

Because it does not mean that the 360 rotation will automatically process the cycle, we will control the cycle by means of the literal volume of the moving object {y: xx}, and then ing to the translateY of the rolling object through correction.
We will also bring you the following:

  • AlloyTouch multi-level Cascade select practice

  • AlloyTouch implements select for 3D Effects

The above is the details of the AlloyTouch infinite loop select plug-in. For more information, see other related articles in the first PHP community!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.