jquery div Drag Effect Sample code

Source: Internet
Author: User

 div Drag effect Presumably everyone has seen it, the implementation of the method is also a lot of, the following for you will be introduced using jquery is how to achieve, interested friends do not miss

The code is as follows: <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "  pageencoding=" Utf-8 "%>  <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  <html xmlns=" http://www.w3.org/1999/xhtml ">  <head>  <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/>  <title> drag div</title>  <style type=" Text/css ">  .show{  Background: #7cd2f8;  width:100px;  height:100px;  text-align:center;  position:absolute;  z-index:1;  left:100px;  top:100px; }    </style>  <script type= "text/ JavaScript "src=". /script/jquery-1.7.2.js "></script>  <script type=" Text/javascript "><!--  $ (document). Ready (function ()   {  $ (". Show"). MouseDown (function (e)//e mouse event   {  $ (this). CSS ("cursor", "move") ;//Change the shape of the mouse pointer     var offset =$ (this). offset ();//div at the location of the page   var x = e.pagex-offset.left;//Get the mouse pointer away from the left edge of the div element   var y = e.pagey-offset.top;/ /Get the distance of the mouse pointer from the top edge of the DIV element   $ (document). Bind ("MouseMove", function (EV)/bound mouse movement event, because the cursor is also effective outside the DIV element, So you want to use the Doucment event without the DIV element event   {  $ (". Show"). After the Stop ()//plus this     var _x = ev.pagex-x;//to get the x-axis move Value & nbsp var _y = ev.pagey-y;//to get the y-axis move value     $ (". Show"). Animate ({left:_x+ "px", top:_y+ "px"},10); });   });    $ (document). MouseUp (function ()   {  $ (". Show"). CSS ("cursor", "Default");  $ ( This). Unbind ("MouseMove"); })  })    //--></script>  </head>  <body >  <div class= "show" >  jquery implementation div Layer drag   </div>  </body>  </html>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.