Javascript code _ javascript tips

Source: Internet
Author: User
The day before yesterday, I made a tree menu and asked to drag it. Very good results. For more information, see. Add:
To disable moving of selected text, FF can set CSS
Xxxx {-moz-user-select: none ;}
Other browsers can set
XXXX. onselectstart = function () {return false}
One implementation principle is to create a placeholder element (or copy a target element, that is, copy B) after clicking the target element ), then drag the target element (or the copied new element B );
After finding the corresponding position, insert the target element. Clear the placeholder element or B.
For example, there is a list:

The Code is as follows:


Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>








  • Article 1

  • Article 2

  • Article 3

  • Article 4

  • Article 5

  • Article 6

  • Article 7

  • Article 8





Click"
  • Article 1
  • "(Recorded as element A), get""
  • Article 1
  • "", Copy Element A (recorded as Element B), insert it into the document, and position Element B absolutely to element, then, when the mouse moves, Element B is dragged to determine the insertion point.
    The insertion point determines the coordinates of the current mouse. If the mouse coordinates fall within the range of other LI elements except Element A, the insertion conditions are met, at the same time, the upper part is inserted to the front, and the lower part is inserted to the back. (=. = My taste is heavy. I think this passage is evil)


    To indicate the insertion position, We can insert another element at the selected insertion point for benchmarking purposes only.
    The following is a demo:

    The Code is as follows:


    Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>








    • Article 1

    • Article 2

    • Article 3

    • Article 4

    • Article 5

    • Article 6

    • Article 7

    • Article 8


    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.