jquery Elastic Cloud Drag calculation function

Source: Internet
Author: User

  jquery Elastic Cloud Drag calculation function

Xian Tian Mutual July on-line the independent research and development of elastic cloud products, the third generation of cloud host new on-line, the new generation of storage architecture security and stability, stronger performance.

Today to share with you the jquery elastic cloud drag calculation function: First HTML page must have, drag elements, drag range, background, and so on.

The drag effect is divided into two types: one is to change the position of the dragged element based on the interval range of the mouse dragging pixels, and the other is to change the drag element as the pixel of the mouse changes.

One is to change the position of the element based on the range of the mouse-dragged pixels: Gets the drag element object at his point under the element event (note here: the point below MouseDown instead of clicking the click) function will drag the range from the left side of the browser to the offset position.

For example: Var pw=$ (Beijing). Offset (). Left; then nested a document's MouseMove move event, in which the x-coordinate of the mouse is the pixel, where the drag element is dragged relative to its parent element, which is the lateral offset of the background range. pixels (mouse x coordinate-the background distance from the left side of the browser), you need to get the corresponding data bar number for example: 1G 2G 3G 4G 5G and so on, each corresponding to an interval, when the mouse dragged to this interval, drag elements into the interval.

The position of the corresponding data (at this point the displacement of the dragged element relative to the background is = mouse displacement-Drag the background displacement-the displacement of the mouse relative to the drag element) is the difference between the horizontal axis.

650) this.width=650; "border=" 1 "src=" http://www.idcs.cn/upload/20147151059103.jpg "width=" 554 "height=" "/>" 650) this.width=650; "border=" 1 "src=" http://www.idcs.cn/upload/20147151059587.jpg "width=" 554 "height=" "/>"

The code is to determine which interval the mouse pixel exists in, the number of times and the same number of data bars, (if you feel that the code can be executed in a variety of loops, depending on the number of cycles to change the corresponding value) interval is calculated: interval pixels = background width pixels/(Data bar number-1). The first data has no left part, and the last data does not have the right part. So the range of the first data should be 0-interval pixels/2, at this time the drag element is placed in the same position as the first data (that is, modify his absolute positioning of the left value), the corresponding data to the value of a text field, the last rule is the same. The middle of the data to determine the pixel range is: background width of pixels/(data bar number-1).

For example, the second data range: the first data interval length to the first data interval length + the normal interval length (pixels), the drag element is placed in and this interval corresponding to the location of the data, the value of the corresponding data to a text field, and so on before the last bar. Then write a document's MouseUp event independently, remove the move event unbind in the event function, or you can do the price calculation here.

The other is that the drag element changes at the same time as the pixel of the mouse:

This is equal to drag the picture with the mouse, there are a lot of tutorials on the web, but only the horizontal drag, and the first way to distinguish less than the evaluation of the proportion of the calculation, just to calculate how many pixels should be the corresponding number of data, this has a ratio of the calculation. Is the total number of data, such as 1 to 100 trillion, every trillion can be selected, there are 100 data. Ratio = Total number of data bars/(Drag range Width-Drag the width of the element). In the drag event of the mouse drag (the coordinates of the middle position of the dragged element are calculated multiplied by the ratio of the drag background) is the number of data corresponding to the current position of the dragged element and writes him to the text field.

Of course there is a click on the background so that the drag element changes, the data in the text field changes, the principle difference is not very big, if the above two steps, change the click event should not be too laborious.

Article from Xi ' an Tianyi Communication Co., Ltd., if you need to purchase elastic cloud Host, please link to our purchase address http://www.idcs.cn/cloud/#ywj.

Welcome to Inquire!

Sales Hotline: 400-675-6239


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.