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 Tags

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)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

jQuery get element padding/margin

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

jQuery Check if Date is Valid

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

10 jQuery Accordions Tabs

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

10 Worth Checking Out jQuery Plugins

HTTP Debugging with Node and http-console HTTP Debugging with Node and http-console Mar 01, 2025 am 01:37 AM

HTTP Debugging with Node and http-console

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

jquery add scrollbar to div

See all articles