Home Web Front-end JS Tutorial jquery draggable form control implementation code_jquery

jquery draggable form control implementation code_jquery

May 16, 2016 pm 06:31 PM
Draggable

So the JQUERY framework needs to be introduced.
Just put my control code into a js file and import it directly
Control code

Copy code The code is as follows:

$.fn.myDrag = function() {
var self = $(this);
self.css("position", "absolute");
var p = self.position();
self.css({ left: p.left, top: p.top });
self.mousedown(
function(event) {
// debugger;
self.data("ifDary", "true"); //Save the state to indicate whether dragging is possible
// debugger;
var selfLeft = event.pageX - parseInt (self.css("left")); //Calculate the left of the mouse to this element
var selfTop = event.pageY - parseInt(self.css("top")); //Calculate the mouse to this The top of the element
self.data("selfLeft", selfLeft); //Save coordinate information
self.data("selfTop", selfTop);
}
);
$( document).mouseup(
function() {
self.data("ifDary", "false");
//Prevent the form from flying outside
var bWidth = $(window) .width();
var bHeight = $(window).height();
var currentleft = parseInt(self.css("left"));
var currenttop = parseInt(self.css( "top"));
if (currentleft <= 0)
currentleft = 0;
if (currentleft >= bWidth)
currentleft = bWidth - self.width();
if (currenttop <= 0)
currenttop = 0;
if (currenttop >= bHeight)
currenttop = bHeight - self.height();
self.css({ left: currentleft, top: currenttop });
}
);
$(document).mousemove(function(event) {
var state = self.data("ifDary");
if (state && state == "true") {
var selfLeft = event.pageX - parseInt(self.data("selfLeft")); //Calculate the left position of this element
var selfTop = event. pageY - parseInt(self.data("selfTop"));
self.css({ left: selfLeft, top: selfTop }); //Set the position of this element
}
});
return self;
}

javascript code
Copy code The code is as follows:

//This is the JQUERY framework, there is no such thing I searched everywhere by myself and stepped on a bunch of them
//This is my control code

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Layui to implement drag-and-drop data visualization dashboard function How to use Layui to implement drag-and-drop data visualization dashboard function Oct 26, 2023 am 11:27 AM

How to use Layui to implement drag-and-drop data visualization dashboard function Introduction: Data visualization is increasingly used in modern life, and the development of dashboards is an important part of it. This article mainly introduces how to use the Layui framework to implement a drag-and-drop data visualization dashboard function, allowing users to flexibly customize their own data display modules. 1. Preparation to download the Layui framework. First, we need to download and configure the Layui framework. You can download it on Layui’s official website (https://www

How to use Layui to implement draggable tab component functionality How to use Layui to implement draggable tab component functionality Oct 26, 2023 pm 01:05 PM

How to use Layui to implement draggable tab component function Layui is a lightweight front-end UI framework that provides rich components and convenient APIs, making front-end development simpler and more efficient. Among them, the tab component is one of the commonly used functions in Layui. In actual development, we often encounter the need to drag and drop tabs to sort or drag to transpose them. This article will introduce how to use Layui to implement the draggable tab component function in the form of examples. First, we need to introduce Layui related

How to use Vue to implement a drag-and-drop visual editor? How to use Vue to implement a drag-and-drop visual editor? Jun 25, 2023 pm 08:22 PM

Vue is a modern JavaScript framework. When implementing a visual editor, it can provide a rich set of components, instructions, life cycle hooks and other functions. It also provides some convenient APIs for the implementation of drag-and-drop interaction. In this article, we will introduce how to use Vue2.x to implement a drag-and-drop visual editor to facilitate web developers to quickly implement corresponding functions in their projects. Component structure First, we need to split the component structure of the visual editor, which usually consists of the following

How to use Layui to implement draggable paging function How to use Layui to implement draggable paging function Oct 25, 2023 pm 12:46 PM

How to use Layui to implement draggable paging function Introduction: In web development, paging function is one of the very common requirements. Layui is a lightweight front-end UI framework that provides a wealth of components and functions that can greatly simplify our development work. In this article, we will introduce how to use Layui to implement drag-and-drop paging function, and provide specific code examples for reference. 1. Basic usage of Layui Before starting, you first need to understand some basic usage methods of Layui. Layui core

How to use Layui to implement draggable tree menu function How to use Layui to implement draggable tree menu function Oct 27, 2023 pm 06:51 PM

Overview of how to use Layui to implement a draggable tree menu: Layui is a simple and easy-to-use front-end framework that provides a wealth of components and plug-ins to facilitate developers to quickly build pages. This article will introduce how to use Layui to implement a draggable tree menu function. We will use the tree component provided by Layui and expand it with a drag-and-drop plug-in to implement the drag-and-drop sorting function of the tree menu. Introducing related resources First, we need to introduce the relevant resource files of Layui, including the Layui framework file

How to use Layui to implement draggable jigsaw puzzle function How to use Layui to implement draggable jigsaw puzzle function Oct 25, 2023 am 11:42 AM

How to use Layui to implement drag-and-drop jigsaw puzzle functionality Jigsaw puzzles are a classic entertainment activity, and many web and mobile applications now offer versions of this game. In this article, we will introduce how to use the Layui framework to implement a drag-and-drop puzzle function and provide specific code examples. Layui is a lightweight front-end framework that provides a set of simplified interface components and rich interactive animation effects. Using the Layui framework, you can quickly develop beautiful and easy-to-use web applications. Fighting to achieve

How to use Layui to implement draggable progress bar function How to use Layui to implement draggable progress bar function Oct 24, 2023 am 11:47 AM

How to use Layui to implement draggable progress bar function Layui is a front-end framework using HTML5 and CSS3. It is easy to use and easy to expand, and is widely used in various web development projects. In the process of using Layui, sometimes we need to implement some specific interactive functions, such as a draggable progress bar. This article will introduce how to use Layui to implement this function and provide specific code examples. First, we need to introduce the relevant resource files of Layui. via online link

How to implement draggable layout in Vue? How to implement draggable layout in Vue? Jun 25, 2023 am 08:48 AM

With the continuous development of Web front-end technology, more and more developers are beginning to use the SPA (Single Page Application) architecture to build applications. As one of the most popular web front-end frameworks currently, Vue provides a rich component library and tools to make it easier to build SPA applications. Vue also provides some convenient solutions when it comes to implementing draggable layouts. 1. Use Vue-Grid-LayoutVue-Grid-Layout is a

See all articles