滑入滑出jq版

初始化

获取dom,提取css中left和top的值,用来以后的操作

var init = function($elem) {
		this.$elem = $elem;
		//parseFloat是去除px字母提取数字的方法
		this.curX = parseFloat(this.$elem.css('left'))
		this.curY = parseFloat(this.$elem.css('top'))
	}

运动模块公共部分

运动函数,传入left值和top值,来决定如何移动

var to = function(x,y, callback) {
        //判断是否传入数值如果没有则将x、y赋值为当前值
		x = typeof x === 'number'? x : this.curX;
		y = typeof y === 'number'? y : this.curY;
		//判断是否已经点击过
		if (this.curX === x && this.curY === y) {return;}
		//发送消息,以在运动过程中添加事件
		this.$elem.trigger('move',[this.$elem])
		//判断是否传入回调函数,如果传入则执行
		if (typeof callback === 'function') {
			callback()
		}
		//更新当前位置
		this.curX = x;
		this.curY = y;
    }

没有动画模式

var Silent=function ($elem) {
		init.call(this, $elem); //改变this的指向,这里this指外面的this,如不使用call,this指init。
        this.$elem.removeClass('transition');
	};

	Silent.prototype.to=function (x,y) {
		var self = this;
        to.call(this, x, y, function() {
        //对目标元素进行位置的更改
            self.$elem.css({
                left: x,
                top: y
            });
            //此处为动画执行完毕
            self.$elem.trigger('moved', [self.$elem]);

        });
	};
	//单独的x轴移动
	Silent.prototype.x=function (x) {
		this.to(x)
	};
	//单独的y轴移动
	Silent.prototype.y=function (y) {
		this.to(y)	
	};

撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G

有动画模式

var Css3 = function($elem) {
        init.call(this, $elem);
        //添加动画的类
        this.$elem.addClass('transition');
        this.$elem.css({
            left: this.curX,
            top: this.curY
        });

    };

    Css3.prototype.to = function(x, y) {
        var self = this;
        to.call(this, x, y, function() {
           //终止上一次事件执行绑定的事件,可以立即执行下一个动作,不需要等待上一个事件执行完毕
           //可以直接使用transitioned
            self.$elem.off(transition.end).one(transition.end, function() {
                self.$elem.trigger('moved', [self.$elem]);
                //     self.$elem.data('status','moved');
                //     self.curX = x;
                //     self.curY = y;
            });

            self.$elem.css({
                left: x,
                top: y
            });

        });
    }
    Css3.prototype.x = function(x) {
        this.to(x);
    };
    Css3.prototype.y = function(y) {
        this.to(null, y);
    };

方便方法调用

//默认不使用css3方式
var defaults = {
			css3: false
		};
    //判断传入的是那个方法,将this指向那方法
    var move = function($elem, options) {
        var mode =null;
         if (options.css3 && transition.isSupport) {
         	mode = new Css3($elem);
         } else {
         	mode = new Silent($elem);
             
         }
          return {
            to: $.proxy(mode.to, mode), //改变指针this指向mode.
			x: $.proxy(mode.x, mode),
			y: $.proxy(mode.y, mode)
         }
    }
  //使用扩展将方法暴露出去
	$.fn.extend({
		move: function (option, x, y) {
                return this.each(function () {
                	var $this = $(this),
                	//将传入的对象赋值
                	options = $.extend({}, defaults, typeof option === 'object' && option),
                	mode = $this.data('move');
                	//判断是否是第一次调用此方法,如果是则将参数赋值给mode
                	if (!mode) {
                		$this.data('move', mode = move($this, options))
                	}
                     //判断执行哪一个方法,没有传入css3方法则使用默认方法
                	if (typeof mode[option] === 'function') {
                		mode[option](x, y)
                	}
                })
		}


完整代码和HTML部分

对代码进行封装方便调用

(function ($) {
	'use strict';
    var transition = window.mt.transition;
	var init = function($elem) {
		this.$elem = $elem;
		//parseFloat是去除px字母提取数字的方法
		this.curX = parseFloat(this.$elem.css('left'))
		this.curY = parseFloat(this.$elem.css('top'))
	}
    
    var to = function(x,y, callback) {
		x = typeof x === 'number'? x : this.curX;
		y = typeof y === 'number'? y : this.curY;
		//判断是否已经点击过
		if (this.curX === x && this.curY === y) {return;}
		this.$elem.trigger('move',[this.$elem])
		if (typeof callback === 'function') {
			callback()
		}
		this.curX = x;
		this.curY = y;
    }
	var Silent=function ($elem) {
		init.call(this, $elem); //改变this的指向,这里this指外面的this,如不使用call,this指init。
        this.$elem.removeClass('transition');
        console.log('有这个类')
	};

	Silent.prototype.to=function (x,y) {
		var self = this;
        to.call(this, x, y, function() {

            self.$elem.css({
                left: x,
                top: y
            });
            self.$elem.trigger('moved', [self.$elem]);

        });
	};
	Silent.prototype.x=function (x) {
		this.to(x)
		
		
	};
	Silent.prototype.y=function (y) {
		this.to(y)	
	};
	

	// css3 方式
	var Css3 = function($elem) {
        init.call(this, $elem);
        this.$elem.addClass('transition');
        console.log('有这个类')
        this.$elem.css({
            left: this.curX,
            top: this.curY
        });

    };

    Css3.prototype.to = function(x, y) {
        var self = this;
        to.call(this, x, y, function() {

            self.$elem.off(transition.end).one(transition.end, function() {
                self.$elem.trigger('moved', [self.$elem]);
                //     self.$elem.data('status','moved');
                //     self.curX = x;
                //     self.curY = y;
            });

            self.$elem.css({
                left: x,
                top: y
            });

        });
    }

    Css3.prototype.x = function(x) {
        this.to(x);
    };
    Css3.prototype.y = function(y) {
        this.to(null, y);
    };


    // js方式
    var Js = function($elem) {
        init.call(this, $elem);
        this.$elem.removeClass('transition');


    };

    Js.prototype.to = function(x, y) {


        var self = this;
        to.call(this, x, y, function() {
            self.$elem.stop().animate({
                left: x,
                top: y
            }, function() {
                self.$elem.trigger('moved', [self.$elem]);
            });
        });
    };

    Js.prototype.x = function(x) {
        this.to(x);

    };
    Js.prototype.y = function(y) {
        this.to(null, y);

    };


	var defaults = {
			css3: false,
			js: false
		};
    //判断传入的是那个方法,将this指向那方法
    var move = function($elem, options) {
        var mode =null;
         if (options.css3 && transition.isSupport) {
         	mode = new Css3($elem);
         } else if (options.js) {
         	mode = new Js($elem);
         } else {
         	mode = new Silent($elem);
             
         }
          return {
            to: $.proxy(mode.to, mode), //改变指针this指向mode.
			x: $.proxy(mode.x, mode),
			y: $.proxy(mode.y, mode)
         }
    }
  
        

	$.fn.extend({
		move: function (option, x, y) {
                return this.each(function () {
                	var $this = $(this),
                	options = $.extend({}, defaults, typeof option === 'object' && option),
                	mode = $this.data('move');
                	if (!mode) {
                		$this.data('move', mode = move($this, options))
                		// console.log(mode)
                	}
                     console.log(option)
                	if (typeof mode[option] === 'function') {
                		
                		mode[option](x, y)
         
                	}
                })
		}
			
	});

})(jQuery)

HTML部分:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <title>运动模块</title>
    <link rel="stylesheet" href="./css/base.css" />
    <link rel="stylesheet" href="./css/common.css" />
    <style>
       .box {
            position: absolute;
            left: 0;
            top: 20px;
            width: 200px;
            height: 100px;
            background-color: red;
        }
        .btns{
            width:100px;
            /*margin-top: 120px;*/
        }

        #box2 {
           
            left: 200px;            
            background-color: yellow;
        }

        .slider{
            overflow: hidden;
            position: relative;
            width:200px;
            height:100px;
            border:2px solid #ccc;
            margin-left:100px;
        }
        .box{
            left:0;
            top:0;
        }
        #box2{
            left:100%;
        }
        #back-btn{
            margin-left:100px;
        }
        
    </style>
    
</head>
<body>
        <div class="slider">
            <div id="box" class="box"></div>
            <div id="box2" class="box"></div>
        </div>     
            <button id="back-btn" class="btns">&lt;</button
            ><button id="go-btn" class="btns">&gt;</button>


        <script src="./js/jquery.js"></script>
        <script src="./js/transition.js"></script>      
        <script src="./js/move.js"></script> 
    
            <script>
                var $box=$('#box'),
                    $box2=$('#box2'),
                    $goBtn=$('#go-btn'),
                    $backBtn=$('#back-btn');
    
                $box.on('move moved',function(e,$elem){
                    console.log(e.type);
                    console.log($elem);
    
                });    
    
                $box.move({
                    css3:false
                }); 
    
                $box2.move({
                    css3:true
                });
        
                 $goBtn.on('click',function () {
                            $box.move('x',-200);
                            $box2.move('x',0);
                }); 
        
                $backBtn.on('click',function () {
                            $box.move('x',0);
                            $box2.move('x',200);
                });   
    </script>   
</body>
</html>

KaTeX数学公式

您可以使用渲染LaTeX数学表达式 KaTeX:

Gamma公式展示 Γ ( n ) = ( n − 1 ) ! ∀ n ∈ N \Gamma(n) = (n-1)!\quad\forall n\in\mathbb N Γ(n)=(n1)!nN 是通过欧拉积分

Γ ( z ) = ∫ 0 ∞ t z − 1 e − t d t &ThinSpace; . \Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,. Γ(z)=0tz1etdt.

你可以找到更多关于的信息 LaTeX 数学表达式here.

新的甘特图功能,丰富你的文章

Mon 06 Mon 13 Mon 20 已完成 进行中 计划一 计划二 现有任务 Adding GANTT diagram functionality to mermaid
  • 关于 甘特图 语法,参考 这儿,

UML 图表

可以使用UML图表进行渲染。 Mermaid. 例如下面产生的一个序列图::

张三 李四 王五 你好!李四, 最近怎么样? 你最近怎么样,王五? 我很好,谢谢! 我很好,谢谢! 李四想了很长时间, 文字太长了 不适合放在一行. 打量着王五... 很好... 王五, 你怎么样? 张三 李四 王五

这将产生一个流程图。:

链接
长方形
圆角长方形
菱形
  • 关于 Mermaid 语法,参考 这儿,

FLowchart流程图

我们依旧会支持flowchart的流程图:

Created with Raphaël 2.2.0 开始 我的操作 确认? 结束 yes no
  • 关于 Flowchart流程图 语法,参考 这儿.

导出与导入

导出

如果你想尝试使用此编辑器, 你可以在此篇文章任意编辑。当你完成了一篇文章的写作, 在上方工具栏找到 文章导出 ,生成一个.md文件或者.html文件进行本地保存。
斜体样式

导入

var move = function($elem, options) {
        var mode =null;
         if (options.css3 && transition.isSupport) {
         	mode = new Css3($elem);
         } else if (options.js) {
         	mode = new Js($elem);
         } else {
         	mode = new Silent($elem);

         }
          return {
            to: $.proxy(mode.to, mode), //改变指针this指向mode.
			x: $.proxy(mode.x, mode),
			y: $.proxy(mode.y, mode)
         }
    }
  

如果你想加载一篇你写过的.md文件或者.html文件,在上方工具栏可以选择导入功能进行对应扩展名的文件导入,
继续你的创作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值