js组件开发流程
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组件开发流程的更多相关文章
- Vue.js的复用组件开发流程
本文由蔡述雄发表 接下来我们会详细分析下如何完成由多个组件组成一个复用组件的开发流程. 下面先看看我们的需求 列表组件quiList.vue 本节我们主要要完成这样一个列表功能,每一行的列表是一个组件 ...
- js组件开发-移动端地区选择控件mobile-select-area
移动端地区选择控件mobile-select-area 由于之前的[js开源组件开发]js手机联动选择地区仿ios 开源git 很受欢迎,于是我又对其进行了一些优化,包括可选的范围变大了,添加了默认空 ...
- winRT Com组件开发流程总结
winRT Com组件开发: 1.编辑idl文件,winRT COM的idl文件与win32的idl文件有差异,如下: interface ItestWinRTClass; runtimeclass ...
- MIP组件开发 自定义js组件开发步骤
什么是百度MIP? MIP(Mobile Instant Pages - 移动网页加速器)主要用于移动端页面加速 官网参考:https://www.mipengine.org/doc/00-mip-1 ...
- 一个简单的Vue.js组件开发示例
//创建属于自己的vue组件库 (function(Vue, undefined) { Vue.component("my-component", { template: '< ...
- Node.js基本开发流程
创建一个hello world: 1.打开一个文本编辑器,在其中输入console.log("hello world"),并保存为hello.js; 注意:输入中文如果编码不是ut ...
- React-Native 组件开发方法
前言 React Native的开发思路是通过组合各种组件来组织整个App,在大部分情况下通过组合View.Image等几个基础的组件,可以非常方便的实现各种复杂的跨平台组件,不过在需要原生功能支持. ...
- 饿了么基于Vue2.0的通用组件开发之路(分享会记录)
Element:一套通用组件库的开发之路 Element 是由饿了么UED设计.饿了么大前端开发的一套基于 Vue 2.0 的桌面端组件库.今天我们要分享的就是开发 Element 的一些心得. 官网 ...
- js组件的写法
工作之中的不足,报了js培训班,因为工作加班原因缺了几天课(js组件开发),现在拾起来补补 <!doctype html> <html> <head> <me ...
随机推荐
- PAT 1009
1009. Product of Polynomials (25) This time, you are supposed to find A*B where A and B are two poly ...
- sql基本语法:
1.create database db_name; --创建数据库 2.drop database db_name; --删除数据库 3.show create database db_name\ ...
- Ant构建和部署项目(转)
原文地址: http://www.blogjava.net/amigoxie/archive/2007/11/09/159413.html Ant是一个Apache基金会下的跨平台的构件工具,它可以实 ...
- PHP之ThinkPHP数据操作CURD
两个数据表 具体操作如下: /**********************数据库操作********************/ ////////添加数据////////// ...
- 关于Eclipse中的开源框架EMF(Eclipse Modeling Framework)
Eclipse项目本身可以划分为4个主要的子项目:Equinox,平台,Java开发工具(Java Development Tools,JDT)和插件开发环境(Plug-in Development ...
- yii2 ./yii command : No such file or directory
git clone下来的yii2后台项目,由于需要执行 ./yii migrate命令.执行之后,提示 No such file or directory 我从同样为yii2 basic的./yii ...
- asp发布至IIS
最近做的一个任务是使用asp写的,显示的是数据库的报表,但是将报表当前目录发布至IIS后,发现还是运行不了 Set conn = Server.CreateObject("ADODB.Con ...
- 几种RAID技术比较
http://book.51cto.com/art/201310/412862.htm RAID(廉价磁盘冗余阵列)技术主要是为了改善磁盘的访问延迟,增强磁盘的可用性和容错能力.目前服务器级别的计算机 ...
- Activiti初学者教程
http://wenku.baidu.com/view/bb7364ad4693daef5ff73d32.html 1. 初识Activiti 1.1. 工作流与工作流引擎 工作流(workflow) ...
- 仿php的日期函数,asp时间处理函数
<% '****************************** '时间处理函数 'FormatDate(Str,DateTime) 'Str 字符串,DateTime 时间 '返回类型为字 ...