How to drag page 1/2 using JavaScript

Source: Internet
Author: User

Translated from:Http://www.webreference.com/programming/javascript/mk/column2/index.html
All Copyrights belong to the original

Javascript is characterized by Dom processing and web page effects. In most cases, we only use the simplest functions of this language, such as creating image carousel/Webpage tabs.ArticleIt will show you how to drag and drop your webpage.

There are many reasons to add the drag-and-drop function to your website. The simplest one is data restructuring. for example, if you have a sequence of content for user sorting, You need to input each entry or select it using select. Instead of dragging the preceding method. maybe your website also needs a navigation window that users can drag! These effects are simple: you can easily implement them!

Dragging on a webpage is not very complicated. First, you need to know the mouse coordinates. Second, you need to know that the user clicks a webpage element and implements dragging. Finally, we need to move this element.

<Br/> <style type = "text/CSS"> Li {margin-bottom: 10px} ol {margin-top: 5px }. dragcontainer {border-Right: #669999 2px solid; padding-Right: 5px; border-top: #669999 2px solid; padding-left: 5px; float: Left; padding-bottom: 0px; margin: 3px; border-left: #669999 2px solid; width: 100px; padding-top: 5px; border-bottom: #669999 2px solid }. overdragcontainer {border-Right: #669999 2px solid; padding-Right: 5px; border-top: #669999 2px solid; padding-left: 5px; float: Left; padding-bottom: 0px; margin: 3px; border-left: #669999 2px solid; width: 100px; padding-top: 5px; border-bottom: #669999 2px solid }. overdragcontainer {background-color: # Eee }. dragbox {border-Right: #000 1px solid; padding-Right: 2px; border-top: #000 1px solid; padding-left: 2px; font-size: 10px; margin-bottom: 5px; padding-bottom: 2px; border-left: #000 1px solid; width: 94px; cursor: pointer; padding-top: 2px; border-bottom: #000 1px solid; font-family: verdana, tahoma, Arial; Background-color: # Eee }. overdragbox {border-Right: #000 1px solid; padding-Right: 2px; border-top: #000 1px solid; padding-left: 2px; font-size: 10px; margin-bottom: 5px; padding-bottom: 2px; border-left: #000 1px solid; width: 94px; cursor: pointer; padding-top: 2px; border-bottom: #000 1px solid; font-family: verdana, tahoma, Arial; Background-color: # Eee }. dragdragbox {border-Right: #000 1px solid; padding-Right: 2px; border-top: #000 1px solid; padding-left: 2px; font-size: 10px; margin-bottom: 5px; padding-bottom: 2px; border-left: #000 1px solid; width: 94px; cursor: pointer; padding-top: 2px; border-bottom: #000 1px solid; font-family: verdana, tahoma, Arial; Background-color: # Eee }. minidragbox {border-Right: #000 1px solid; padding-Right: 2px; border-top: #000 1px solid; padding-left: 2px; font-size: 10px; margin-bottom: 5px; padding-bottom: 2px; border-left: #000 1px solid; width: 94px; cursor: pointer; padding-top: 2px; border-bottom: #000 1px solid; font-family: verdana, tahoma, Arial; Background-color: # Eee }. overdragbox {background-color: # ffff99 }. dragdragbox {background-color: # ffff99 }. dragdragbox {filter: alpha (opacity = 50); background-color: # ff99cc} legend {font-weight: bold; font-size: 12px; color: #666699; font-family: verdana, tahoma, Arial} fieldset {padding-Right: 3px; padding-left: 3px; padding-bottom: 3px; padding-top: 3px }. history {font-size: 10px; overflow: auto; width: 100%; font-family: verdana, tahoma, Arial; Height: 82px} # dragcontainer8 {border-right: #669999 1px solid; padding-Right: 0px; border-top: #669999 1px solid; padding-left: 5px; padding-bottom: 0px; border-left: #669999 1px solid; width: 110px; padding-top: 5px; border-bottom: #669999 1px solid; Height: 110px }. minidragbox {float: Left; margin: 0px 5px 5px 0px; width: 20px; Height: 20px} Pre {border-Right: # CCC 1px solid; padding-Right: 10px; border-top: # CCC 1px solid; padding-left: 10px; padding-bottom: 10px; border-left: # CCC 1px solid; padding-top: 10px; border-bottom: # CCC 1px solid; Background-color: # f8f8f0 }</style> <fieldset id = "demo4"> <legend> example-drag a page element </legend> item #1 item #2 item #3 item #4 item #5 item #6 item #7 item #8 item #9 item #10 item #11 item #12 </fieldset> <p>

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.