js realizes the special effect of clicking and dropping. Let’s take a look at the effect picture first Without further ado, let’s get started. <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> <script src="jquery.js"></script> <script> window.onload = function () { var str = ''; var len = 20; var aDiv = document.getElementsByTagName('div'); var timer = null; var num = 0; for ( var i=0; i<len; i++ ) { str += '<div style="width:50px; height:50px; background:red; position:absolute; top:0px; left:'+ i*60 +'px;"></div>'; } document.body.innerHTML = str; document.onclick = function () { clearInterval( timer ); timer = setInterval( function () { DM( aDiv[num], 'top', 23, 500 ); num++; if ( num === len ) { clearInterval( timer ); } }, 100 ); }; }; </script> </head> <body> </body> </html> I quoted the encapsulation method here function DM( obj, attr, dir, target, endFn ) { dir = parseInt(getStyle( obj, attr )) < target ? dir : -dir; clearInterval( obj.timer ); obj.timer = setInterval(function () { var speed = parseInt(getStyle( obj, attr )) + dir; // step length if ( speed > target && dir > 0 || speed < target && dir < 0 ) { speed = target; } obj.style[attr] = speed + 'px'; if ( speed == target ) { clearInterval( obj.timer ); /* if ( endFn ) { endFn(); } */ endFn && endFn(); } }, 30); } This is the end of this article about how to implement click-and-drop effects with JS. For more relevant js click-and-drop content, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to implement Docker container self-start
>>: Solution to mysql failure to start due to insufficient disk space in ubuntu
1. Introduction to Animate.css Animate.css is a r...
Regarding uninstalling the previously installed v...
I recently encountered a problem. The emoticons o...
There is a project developed on Mac, and the pack...
Source: http://www.ruoyi.vip/ import Vue from ...
The answer you often hear is that using a NULL va...
Table of contents 1. WordPress deployment 1. Prep...
<br />For each of our topics, the team will ...
Last time, a very studious fan asked if it was po...
1 Introduction to HTML 1.1 First experience with ...
Table of contents Brief description: 1. Four char...
CSS controls the printing style of web pages : Use...
Single page application characteristics "Ass...
1. Download the virtual machine version 15.5.1 I ...
question: <input type="hidden" name=...