Home
Web Front-end
JS Tutorial
Copy and write effect of mouse dragging elements based on jquery_jquery



Copy and write effect of mouse dragging elements based on jquery_jquery
May 16, 2016 pm 06:03 PM
Mouse drag
直接上代码:
复制代码 代码如下:
<!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>鼠标拖拽复制效果</title>
<style>
body{ line-height:150% }
.show{ display:block}
.hide{ display:none}
.clone{position: absolute; border:1px solid #666; background-color:#CCCCCC;}
.over{ border:1px solid #666;}
#left{ float:left; width:200px; border:1px solid #666;}
#left li.selected{ background-color:#CCCCCC}
#right{ margin-left:220px; border:1px solid #666;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(function(){
$("#left li").click(function(e) {
var index=$(this).index();
$("#left li").removeClass("selected");
$(this).addClass("selected");
$("#right ul").removeClass('show');
$("#right ul").addClass('hide');
$("#right ul").eq(index).removeClass('hide');
$("#right ul").eq(index).addClass('show');
});
$("#left ul li").mousemove(function(e) {
if($(this).attr('class')!='selected'&&$(".clone").length>0)
{
$(this).addClass('over');
}
});
$("#left ul li").mouseout(function(e) {
if($(this).attr('class')!='selected')
{
$(this).removeClass('over');
}
});
$("#left ul li").mouseup(function(e) {
if($(this).attr('class')!='selected'&&$(".clone").length>0)
{
var index=$(this).index();
//$("#right ul").eq(index).prepend($(".clone"));
$(".clone").appendTo($("#right ul").eq(index));
$(".clone").attr('class','');
}
});
$("#right ul li").mousedown(function(e) {//鼠标按下,鼠标变移动标志,克隆元素,并确定新克隆元素位置
$(this).clone().addClass("clone").appendTo($("body"));
$("body").css('cursor','move');
$(".clone").css('left',e.clientX 1);
$(".clone").css('top',e.clientY 1);
});
$(document).mousemove(function(e){
if($(".clone").length>0)
{
$(".clone").css('left',e.clientX 1);
$(".clone").css('top',e.clientY 1);
}
});
$(document).mouseup(function(e){
$(".clone").remove();
$("body").css('cursor','auto');
});
});
</script>
</head>
<body>
<div id="left">
<ul>
<li class="selected">组一</li>
<li>组2</li>
<li>组3</li>
</ul>
</div>
<div id="right">
<ul class="show">
<li>1姓名一</li>
<li>1姓名2</li>
<li>1姓名3</li>
<li>1姓名4</li>
<li>1姓名5</li>
<li>1姓名6</li>
</ul>
<ul class="hide">
<li>2姓名一</li>
<li>2姓名2</li>
<li>2姓名3</li>
<li>2姓名4</li>
<li>2姓名5</li>
<li>2姓名6</li>
</ul>
<ul class="hide">
<li>3姓名一</li>
<li>3姓名2</li>
<li>3姓名3</li>
<li>3姓名4</li>
<li>3姓名5</li>
<li>3姓名6</li>
</ul>
</div>
</body>
</html>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

HTTP Debugging with Node and http-console

Custom Google Search API Setup Tutorial
