原生js拖拽(面向对象)

代码地址:http://files.cnblogs.com/files/fxnet/%E5%8E%9F%E7%94%9Fjs%E6%8B%96%E6%8B%BD%EF%BC%88%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%EF%BC%89.rar

<style>
img
{
width: 200px;
height: 200px;
}
.fx_drag
{
background: green;
width: 300px;
height: 500px;
float: left;
}
p
{
float: left;
margin-top: 0;
}
p img
{
float: left;
}
#end, #end2
{
background: red;
width: 300px;
height: 500px;
float: left;
margin-left: 500px;
}
.imgMoveing
{
position: absolute;
cursor: move;
}
.imgEnd
{
position: absolute;
transition: all 1s;
}
.div1
{
float: left;
width: 100%;
margin-bottom: 20px;
}
</style>
<div class="div1">
<div id="star" class="fx_drag">
<p>
<img draggable="false" fx_drag="true" src="46354375_950.jpg" /></p>
<p>
<img draggable="false" fx_drag="true" src="Focus_Monster-821_Concept-01_634x357_[634x357]8488546.png" /></p>
<p>
<span fx_drag="true">adasdadasd</span>
</p>
</div>
<div id="end">
</div>
</div>
<div>
<div id="star2" class="fx_drag">
<p>
<img draggable="false" fx_drag="true" src="46354375_950.jpg" /></p>
<p>
<img draggable="false" fx_drag="true" src="Focus_Monster-821_Concept-01_634x357_[634x357]8488546.png" /></p>
<p>
<span fx_drag="true">adasdadasd</span>
</p>
</div>
<div id="end2">
</div>
</div>
<script>
Object.extend = function (destination, source) {
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var drag = function (options) {
var div_star;
var div_end;
this.options = {};
if (typeof options == "string") {
this.options.div_star = document.querySelector(options);
this.options.div_end = document.getElementById("end");
this.options.cloneNode = false;
}
else
this.options = Object.extend(this.options, options);
this.init();
}
drag.prototype.init = function () {
var self = this;
this.params = {
drag_star: false, //是否开始拖放
drag_success: false, //是否进入拖放区域
div_end: self.options.div_end, //目标容器
div_end_params: {
x: self.options.div_end.offsetLeft, //容器的所在位置x
y: self.options.div_end.offsetTop, //容器的所在位置y
width: self.options.div_end.offsetWidth, //容器宽度
height: self.options.div_end.offsetHeight//容器高度
},
move_obj: {}
};
var drag_list = self.options.div_star.querySelectorAll("[fx_drag=true]");
for (var i = 0; i < drag_list.length; i++) {
drag_list[i].onmousedown = function () {
self.fx_drag('star', event, this);
}
drag_list[i].onmousemove = function () {
self.fx_drag('move', event, this);
}
drag_list[i].onmouseup = function () {
self.fx_drag('end', event, this);
}
drag_list[i].onmouseout = function () {
self.fx_drag('end', event, this);
}
}
}
drag.prototype.fx_drag = function (type, event, obj) {
switch (type) {
case "star":
if (obj.className == "") {
this.params.drag_star = true; //鼠标已经按下
this.params.move_obj.x = event.x; //鼠标所在位置x
this.params.move_obj.y = event.y; //鼠标所在位置y
this.params.move_obj.offset = { x: obj.offsetLeft, y: obj.offsetTop }; //元素所在位置x,y
this.params.move_obj.width = obj.offsetWidth; //图片宽度
this.params.move_obj.height = obj.offsetHeight; //图片高度
}
break;
case "move":
if (this.params.drag_star) {
obj.className = "imgMoveing"; //设置图片的样式为拖动中样式
var XX = event.x - this.params.move_obj.x; //鼠标位置-鼠标落下位置=实际拖动像素x
var YY = event.y - this.params.move_obj.y; //鼠标位置-鼠标落下位置=实际拖动像素y
var NowX = this.params.move_obj.offset.x + XX; //图片原始位置+拖动像素x=当前图片应在位置x
var NowY = this.params.move_obj.offset.y + YY; //图片原始位置+拖动像素x=当前图片应在位置y
obj.style.left = NowX; //设置图片位置
obj.style.top = NowY; //设置图片位置
//判断图片是否进入容器
if (NowX > this.params.div_end_params.x && NowX < this.params.div_end_params.x + this.params.div_end_params.width - this.params.move_obj.width
&& NowY > this.params.div_end_params.y && NowY < this.params.div_end_params.y + this.params.div_end_params.height - this.params.move_obj.height)
this.params.drag_success = true;
else
this.params.drag_success = false;
}
break;
case "end":
//鼠标按下才会触发
if (!this.params.drag_star)
return;
this.params.drag_star = false;
//如果进入容器 把图片加入容器 并且把当前图片所有拖动属性清空
if (this.params.drag_success) {
if (this.options.cloneNode) {
var newNode = obj.parentNode.cloneNode(true);
newNode.children[0].onmousedown = null;
newNode.children[0].onmousemove = null;
newNode.children[0].onmouseup = null;
newNode.children[0].className = "";
newNode.children[0].removeAttribute("style");
newNode.children[0].removeAttribute("fx_drag");
this.params.div_end.appendChild(newNode);

obj.style.left = this.params.move_obj.offset.x;
obj.style.top = this.params.move_obj.offset.y;
obj.className = "";
} else {
obj.onmousedown = null;
obj.onmousemove = null;
obj.onmouseup = null;
obj.className = "";
this.params.div_end.appendChild(obj.parentNode);
}
this.params.move_obj = {};
} else {
//没有进入容器 按原位置返回,并且加入返回时间 1s内返回
obj.className = "imgEnd";
var self = this;
setTimeout(function () {
obj.style.left = self.params.move_obj.offset.x;
obj.style.top = self.params.move_obj.offset.y;
self.params.move_obj = {};
}, 20);
setTimeout(function () {
obj.className = "";
}, 1000);
}
break;
}
return false;
}
var aa = new drag("#star");
var bb = new drag({
div_star: document.getElementById("star2"),
div_end: document.getElementById("end2"),
cloneNode:true
});

console.log(aa);
console.log(bb);

</script>

http://files.cnblogs.com/files/fxnet/%E5%8E%9F%E7%94%9Fjs%E6%8B%96%E6%8B%BD%EF%BC%88%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%EF%BC%89.rar

转载于:https://www.cnblogs.com/fxnet/p/5910258.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园信息化系统解决方案旨在通过先进的信息技术,实现教育的全方位创新和优质资源的普及共享。该方案依据国家和地方政策背景,如教育部《教育信息化“十三五”规划》和《教育信息化十年发展规划》,以信息技术的革命性影响为指导,推进教育信息化建设,实现教育思想和方法的创新。 技术发展为智慧校园建设提供了强有力的支撑。方案涵盖了互连互通、优质资源共享、宽带网络、移动APP、电子书包、电子教学白板、3D打印、VR虚拟教学等技术应用,以及大数据和云计算技术,提升了教学数据记录和分析水平。此外,教育资源公共服务平台、教育管理公共服务平台等平台建设,进一步提高了教学、管控的效率。 智慧校园系统由智慧教学、智慧管控和智慧办公三大部分组成,各自具有丰富的应用场景。智慧教学包括微课、公开课、精品课等教学资源的整合和共享,支持在线编辑、录播资源、教学分析等功能。智慧管控则通过平安校园、可视对讲、紧急求助、视频监控等手段,保障校园安全。智慧办公则利用远程视讯、无纸化会议、数字会议等技术,提高行政效率和会议质量。 教育录播系统作为智慧校园的重要组成部分,提供了一套满足学校和教育局需求的解决方案。它包括标准课室、微格课室、精品课室等,通过自动五机位方案、高保真音频采集、一键式录课等功能,实现了优质教学资源的录制和共享。此外,录播系统还包括互动教学、录播班班通、教育中控、校园广播等应用,促进了教育资源的均衡化发展。 智慧办公的另一重点是无纸化会议和数字会议系统的建设,它们通过高效的文件管理、会议文件保密处理、本地会议的音频传输和摄像跟踪等功能,实现了会议的高效化和集中管控。这些系统不仅提高了会议的效率和质量,还通过一键管控、无线管控等设计,简化了操作流程,使得会议更加便捷和环保。 总之,智慧校园信息化系统解决方案通过整合先进的信息技术和教学资源,不仅提升了教育质量和管理效率,还为实现教育均衡化和资源共享提供了有力支持,推动了教育现代化的进程。
智慧校园信息化系统解决方案旨在通过先进的信息技术,实现教育的全方位创新和优质资源的普及共享。该方案依据国家和地方政策背景,如教育部《教育信息化“十三五”规划》和《教育信息化十年发展规划》,以信息技术的革命性影响为指导,推进教育信息化建设,实现教育思想和方法的创新。 技术发展为智慧校园建设提供了强有力的支撑。方案涵盖了互连互通、优质资源共享、宽带网络、移动APP、电子书包、电子教学白板、3D打印、VR虚拟教学等技术应用,以及大数据和云计算技术,提升了教学数据记录和分析水平。此外,教育资源公共服务平台、教育管理公共服务平台等平台建设,进一步提高了教学、管控的效率。 智慧校园系统由智慧教学、智慧管控和智慧办公三大部分组成,各自具有丰富的应用场景。智慧教学包括微课、公开课、精品课等教学资源的整合和共享,支持在线编辑、录播资源、教学分析等功能。智慧管控则通过平安校园、可视对讲、紧急求助、视频监控等手段,保障校园安全。智慧办公则利用远程视讯、无纸化会议、数字会议等技术,提高行政效率和会议质量。 教育录播系统作为智慧校园的重要组成部分,提供了一套满足学校和教育局需求的解决方案。它包括标准课室、微格课室、精品课室等,通过自动五机位方案、高保真音频采集、一键式录课等功能,实现了优质教学资源的录制和共享。此外,录播系统还包括互动教学、录播班班通、教育中控、校园广播等应用,促进了教育资源的均衡化发展。 智慧办公的另一重点是无纸化会议和数字会议系统的建设,它们通过高效的文件管理、会议文件保密处理、本地会议的音频传输和摄像跟踪等功能,实现了会议的高效化和集中管控。这些系统不仅提高了会议的效率和质量,还通过一键管控、无线管控等设计,简化了操作流程,使得会议更加便捷和环保。 总之,智慧校园信息化系统解决方案通过整合先进的信息技术和教学资源,不仅提升了教育质量和管理效率,还为实现教育均衡化和资源共享提供了有力支持,推动了教育现代化的进程。
原生 JavaScript 中,可以通过构造函数和原型链来实现面向对象继承。具体实现方式如下: 1. 构造函数继承 构造函数继承是通过在子类构造函数中调用父类构造函数来实现的。这种方式的缺点是无法继承父类原型上的方法和属性。 ```javascript function Parent(name) { this.name = name; } function Child(name, age) { Parent.call(this, name); this.age = age; } var child = new Child('Tom', 18); console.log(child.name); // Tom console.log(child.age); // 18 ``` 2. 原型链继承 原型链继承是通过将子类的原型指向父类的实例来实现的。这种方式的缺点是所有子类实例共享父类实例上的属性和方法。 ```javascript function Parent() { this.name = 'parent'; } Parent.prototype.sayHello = function() { console.log('Hello'); }; function Child() {} Child.prototype = new Parent(); var child1 = new Child(); var child2 = new Child(); console.log(child1.name); // parent console.log(child2.name); // parent child1.sayHello(); // Hello child2.sayHello(); // Hello ``` 3. 组合继承 组合继承是将构造函数继承和原型链继承结合起来使用的一种方式。这种方式既可以继承父类实例上的属性和方法,也可以继承父类原型上的属性和方法。 ```javascript function Parent(name) { this.name = name; } Parent.prototype.sayHello = function() { console.log('Hello'); }; function Child(name, age) { Parent.call(this, name); this.age = age; } Child.prototype = new Parent(); Child.prototype.constructor = Child; var child = new Child('Tom', 18); console.log(child.name); // Tom console.log(child.age); // 18 child.sayHello(); // Hello ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值