html代码

<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>

css样式

#div1{
width: 100px;
height: 100px;
background: red;
cursor: move;
position:absolute;
left:;
top:;
}
#div2{
width: 100px;
height: 100px;
background: black;
cursor: move;
position:absolute;
left:100px;
top:;
}
#div3{
width: 100px;
height: 100px;
background: blue;
cursor: move;
position:absolute;
left:200px;
top:;
}

js代码

<script>
window.onload=function(){
var oDiv1=new Drag();
oDiv1.init({
id:'div1'
}); var oDiv2=new Drag();
oDiv2.init({
id:'div2',
fD:function(){
document.title="hi"
}
}); var oDiv3=new Drag();
oDiv3.init({
id:'div3',
fD:function(){
document.title='jerry'
},
fU:function(){
document.title='byebye'
}
});
}
function Drag(){
this.oDiv=null;
this.disX=0;
this.disY=0; this.settings={
fD:function(){},
fU:function(){}
}
} Drag.prototype.init=function(opt){
var _this=this; extend(this.settings,opt); this.oDiv=document.getElementById(opt.id);
this.oDiv.onmousedown=function(ev){
var ev=ev || window.event;
_this.fnDown(ev);
_this.settings.fD(); document.onmousemove=function(ev){
var ev=ev || window.event;
_this.fnMove(ev);
}
document.onmouseup=function(){
_this.fnUp();
_this.settings.fU();
} return false;
}
}
Drag.prototype.fnDown=function(ev){
var ev=ev || window.event;
this.disX=ev.clientX-this.oDiv.offsetLeft;
this.disY=ev.clientY-this.oDiv.offsetTop;
}
Drag.prototype.fnMove=function(ev){
this.oDiv.style.left=ev.clientX-this.disX+'px';
this.oDiv.style.top=ev.clientY-this.disY+'px';
}
Drag.prototype.fnUp=function(){
document.onmousedown=null;
document.onmousemove=null;
} function extend(obj1,obj2){
for (var i in obj2){
obj1[i]=obj2[i];
}
}
</script>

js组件开发流程的更多相关文章

  1. Vue.js的复用组件开发流程

    本文由蔡述雄发表 接下来我们会详细分析下如何完成由多个组件组成一个复用组件的开发流程. 下面先看看我们的需求 列表组件quiList.vue 本节我们主要要完成这样一个列表功能,每一行的列表是一个组件 ...

  2. js组件开发-移动端地区选择控件mobile-select-area

    移动端地区选择控件mobile-select-area 由于之前的[js开源组件开发]js手机联动选择地区仿ios 开源git 很受欢迎,于是我又对其进行了一些优化,包括可选的范围变大了,添加了默认空 ...

  3. winRT Com组件开发流程总结

    winRT Com组件开发: 1.编辑idl文件,winRT COM的idl文件与win32的idl文件有差异,如下: interface ItestWinRTClass; runtimeclass ...

  4. MIP组件开发 自定义js组件开发步骤

    什么是百度MIP? MIP(Mobile Instant Pages - 移动网页加速器)主要用于移动端页面加速 官网参考:https://www.mipengine.org/doc/00-mip-1 ...

  5. 一个简单的Vue.js组件开发示例

    //创建属于自己的vue组件库 (function(Vue, undefined) { Vue.component("my-component", { template: '< ...

  6. Node.js基本开发流程

    创建一个hello world: 1.打开一个文本编辑器,在其中输入console.log("hello world"),并保存为hello.js; 注意:输入中文如果编码不是ut ...

  7. React-Native 组件开发方法

    前言 React Native的开发思路是通过组合各种组件来组织整个App,在大部分情况下通过组合View.Image等几个基础的组件,可以非常方便的实现各种复杂的跨平台组件,不过在需要原生功能支持. ...

  8. 饿了么基于Vue2.0的通用组件开发之路(分享会记录)

    Element:一套通用组件库的开发之路 Element 是由饿了么UED设计.饿了么大前端开发的一套基于 Vue 2.0 的桌面端组件库.今天我们要分享的就是开发 Element 的一些心得. 官网 ...

  9. js组件的写法

    工作之中的不足,报了js培训班,因为工作加班原因缺了几天课(js组件开发),现在拾起来补补 <!doctype html> <html> <head> <me ...

随机推荐

  1. Mysql 5.5 replication 多数据库主从备份Master-Slave配置总结

    配置Mysql server 5.5 的双机备份,也就是master-slave模式.本例子还是一个多database复制的情况. 现在有两个database在同一台mysql server,也就是m ...

  2. [Practical Git] Remove unnecessary git tracking with .gitignore files

    Most projects have automatically generated files or folders from the operating system, applications, ...

  3. 字符编码的故事(ASCII,ANSI,Unicode,Utf-8区别)转载

    http://www.imkevinyang.com/2009/02/字符编解码的故事(ascii,ansi,unicode,utf-8区别).html 很久很久以前,有一群人,他们决定用8个可以开合 ...

  4. C#_delegate和事件 - 如果金额小于0则触发事件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. 去掉Eclipse中的Validating

    去掉Eclipse中的Validating 最近我的Eclipse一直经常效验javascript,我疯了校验了一个多小时还是在验.我只能在项目的.project文件中: 去掉.project文件中的 ...

  6. Fixflow引擎解析(五)(内核) - 基于Token驱动的引擎内核运转原理

    Fixflow内核运转图v1.0(beta) 未完待续.........

  7. c++ 拷贝构造练习

    #include<iostream> using namespace std; class Vector { private: int *dwp; int size; void clone ...

  8. 在eclipse中运行storm-starter

    开源软件官网提供的demo无疑是学习开源软件的最好的最原始的样例. 在Storm官网里下载apache-storm-0.9.6.zip,里面\examples\storm-starter\src\jv ...

  9. BigInteger

    首先上模板(不断更新中...)(根据刘汝佳AOAPCII修改) #include <iostream> #include <sstream> #include <cstd ...

  10. 【Objective-C】0-第一个OC的类

    OC是一门面向对象的语言,因此它也有类.对象.静态\动态方法.成员变量的概念.这讲就来创建第一个OC的类. 一.语法简介 1.类 在Java中,我们用1个.java文件就可以描述清楚一个类:在OC中, ...