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 ...
随机推荐
- sql server char nchar nvarchar varchar之間的區別
char存储固定长度的字符串,最大长度为8000个字节. varchar存储可变长度的字符串.最大长度为8000个字节. nchar存储固定长度的Unicode字符串,最大长度为4000个字符. nv ...
- location查询字符串解析
function getQueryStringArgs() { //取得查询字符串并去掉开头的问号 var qs = (location.search.length >0? location.s ...
- C# 之 服务端获取远程资源
获取指定网页的远程资源可使用 WebClient.WebRequest.HttpWebRequest 三种方式来实现.当然也可使用webBrowse,webBrowse不做介绍. 通过 System. ...
- VB.net 利用SerialPort进行读取串口操作
Imports SystemImports System.IO.Ports Public Class Form1 Private Sub Form1_Load(ByVal sender As Syst ...
- JAVA_Gson_example
package cn.kjxy.GSON; import java.util.List; import cn.kjxy.JSON.HttpHelpers; import com.google.gson ...
- jquery循环遍历radio单选按钮,并设置选中状态
背景:自己在做项目过程中遇到的问题,现在记录一下. 需求:在ajax获取后台数据的之后,需要根据获取的数据对页面中的radio单选按钮进行选中状态设置 因为自身js功底欠佳,所以耽误了点时间,现在把方 ...
- nginx笔记----安装
nginx的安装 ./configure make && make install (一)准备条件: 1.GCC---gun编译器集合 Nginx是一个由C语言编写的程序,因此首先需要 ...
- CCLablettf读取显示xml文件内容显示中文
CCDictionary *strings = CCDictionary::createWithContentsOfFile("tips2.xml"); const char *h ...
- css3过度和动画
一.过度(transition) transition:[transition-property] || [transition-duration] || [transition-timing-fun ...
- spark下测试akka的分布式通讯功能
采用的spark版本为1.1.0 scala版本为2.10.4 编写scala类文件myactors.scala: package bluejoe import akka.actor._ import ...