拖拽组件3--转秒味课堂课件

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<style>
#div1{ width:100px; height:100px; background:red; position:absolute;}
#div2{ width:100px; height:100px; background:yellow; position:absolute; left:100px;}
#div3{ width:100px; height:100px; background:blue; position:absolute; left:200px;}
#div4{ width:100px; height:100px; background:green; position:absolute; left:300px;}
</style>
<script>

//组件开发 : 多组对象,像兄弟之间的关系( 代码复用的一种形式 )

window.onload = function(){

    var d1 = new Drag();
    d1.init({    //配置参数
        id : ‘div1‘
    });

    var d2 = new Drag();
    d2.init({   //配置参数
        id : ‘div2‘,
        toDown : function(){
            document.title = ‘hello‘;
            document.body.style.background = ‘black‘;
        }
    });

    var d3 = new Drag();
    d3.init({    //配置参数
        id : ‘div3‘,
        toDown : function(){
            document.title = ‘妙味‘;
        },
        toUp : function(){
            document.title = ‘课堂‘;
        }
    });

    var d4 = new Drag();
    d4.init({    //配置参数
        id : ‘div4‘,
        toUp : function(){
            document.title = ‘beybye‘;
        }
    });

};

function Drag(){
    this.obj = null;
    this.disX = 0;
    this.disY = 0;

    this.settings = {   //默认参数
        toDown : function(){},
        toUp : function(){}
    };

}
Drag.prototype.init = function(opt){

    var This = this;

    this.obj = document.getElementById(opt.id);

    extend( this.settings , opt );

    this.obj.onmousedown = function(ev){
        var ev = ev || window.event;
        This.fnDown(ev);

        This.settings.toDown();

        document.onmousemove = function(ev){
            var ev = ev || window.event;
            This.fnMove(ev);
        };
        document.onmouseup = function(){
            This.fnUp();

            This.settings.toUp();

        };
        return false;
    };

};

Drag.prototype.fnDown = function(ev){
    this.disX = ev.clientX - this.obj.offsetLeft;
    this.disY = ev.clientY - this.obj.offsetTop;
};
Drag.prototype.fnMove = function(ev){
    this.obj.style.left = ev.clientX - this.disX + ‘px‘;
    this.obj.style.top = ev.clientY - this.disY + ‘px‘;
};
Drag.prototype.fnUp = function(){
    document.onmousemove = null;
    document.onmouseup = null;
};

function extend(obj1,obj2){
    for(var attr in obj2){
        obj1[attr] = obj2[attr];
    }
}

</script>
</head>

<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
</body>
</html>
时间: 2024-10-12 03:02:43

拖拽组件3--转秒味课堂课件的相关文章

弹窗组件1--转秒味课堂课件

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <style> *{ margin:0; padding:0;} .login{ background:white; border:1px #000

弹窗拖拽组件开发应用

需要注意的问题包括: 1.this的指向到底是指向谁--弄清楚所指的对象 2.深入理解原型的概念及使用: 去改写对象下面公用的方法或者属性 , 让公用的方法或者属性在内存中存在一份 ( 提高性能) 1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 5 <

自定义事件拖拽组件

<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>自定义事件拖拽组件</title> <style> #div1{ width:100px; height:100px; background:red; position:abs

vue2-dragula vue拖拽组件

Drag and drop so simple it hurts Vue wrapper for dragula drag'n drop library, based on vue-dragula by @Astray-git. vue 为 dragula 拖拽 包装 减少 代码,基于   vue-dragula. This library has been refactored, upgraded and extended with powerful new features for use

vue实现拖拽组件

可以拖拽,靠边停靠,效果图如下 代码如下: 注意:代码中使用的图片未上传 DragAndDrop组件: <template> <div class="drag" id="moveDiv" @mousedown="start($event)" @touchstart="start($event)" @mousemove="move($event)" @touchmove="move

Vue 组件总结 (一、拖拽组件 Vue-draggable)

一.vue-draggable 安装使用npm地址: https://www.npmjs.com/package/vuedraggable 二.表格拖拽使用, 举例: <table class="table table-condensed"> <thead> <tr> <th>视频ID</th> <th>名称</th> <th>作者</th> <th>创建时间<

Vue+element 需要用到拖拽组件 vuedraggable

新需求是要求界面上的14个可以拖拽,点击保存之后保存拖拽之后的顺序. 确定需求之后肯定第一时间是百度,发现有个插件vuedragger拖拽,按照教程就懵懂的开始了. 官方示例:https://david-desmaisons.github.io/draggable-example/ 1.安装 npm install vuedraggable 2.引入 import draggable from 'vuedraggable' 3.注册 components: { draggable } html

秒味课堂Angular js笔记------$scope.$watch和$scope.$apply

$scope.$watch(watchFn , watchAction , deepWatch) 其中,watchFn是带有angular表达式或函数字符串: watchAction是一个函数或者表达式,当watchFn发生变化时调用,如果是函数,其签名是function(newValue, oldValue, scope): deepWatch如果是ture,则会检查被监控对象的每一个属性是否发生了变化. <script type="application/javascript"

弹出框组件,可拖拽

/** * 弹出框组件 */ (function($) { var Utils = { showMask: function() { var $mask = $("#mask"); if( $mask.length === 0 ) { $('body').prepend("<div id='mask' class='mask'></div>"); } $("#mask").css({ width: Math.max(doc