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. jquery美化滚动条插件jscrollpane应用(转)

    原文地址:http://www.jqcool.net/jquery-jscrollpane.html jScrollPane是一个设计非常灵活的跨浏览器的jQuery ,它将浏览器的默认滚动条或是元素 ...

  2. [VirtualBox] Install Ubuntu 14.10 error 5 Input/output error

    After you download the VirtualBox install package and install it (just defualt setting). Then you sh ...

  3. [MODx] 6. Cache '!' with login package

    1. Install login package. 2. Create a Template called 'login': [[!Login? &loginResourceId=`13` / ...

  4. android125 zhihuibeijing 缓存

    ## 三级缓存 ## - 内存缓存, 优先加载, 速度最快 - 本地缓存(内存卡), 次优先加载, 速度快 - 网络缓存, 不优先加载, 速度慢,浪费流量 package com.itheima.zh ...

  5. js hash字符串转成json

    var a='account.type=1&account.id=&account.dependFlag=0&account.card.companyId=1&acco ...

  6. 优化sql,返回行数少情况下,NL比hash快好多

    sql如下 select t.id, t.value, tt.sort as sortno from ENGINEERING_TYPE t left join ENGINEERING_TYPE tt ...

  7. Java基础知识强化之IO流笔记65:序列化流 和 反序列化流

    1. 什么是 序列化 和 反序列化 ?     序列化 (Serialization):将对象的状态信息转换为可以存储或传输的形式的过程.比如转化为二进制.xml.json等的过程. 在序列化期间,对 ...

  8. five kinds of IPC methods

    Shared memory permits processes to communicate by simply reading and writing to a specified memory l ...

  9. hadoop的相关资料链接

    hadoop的资料整理博客 http://www.itpub.net/thread-1588509-1-1.html

  10. MATLAB的基本元素

    MALTAB程序的基本数据单元是数组,MATLAB 的变量名必须以字母开头,后面可以跟字母,数字和下划线(_).只有前31个字符是有效的:如果超过了31 个字符,基余的字符将被忽略.如果声明两个变量, ...