zoukankan      html  css  js  c++  java
  • mass Framework flip插件

    如果浏览器支持CSS3 transform 3D的话,我们可以玩许多东西,比如flip,即电子书软件的那种翻页效果。不过,像transform3D的高级东西,不是一般浏览器能玩转,更别提IE9了。因此这时轮到JS出马了。jQuery上素以插件多出名,在上面找了几个相关插件研究一翻,搞出了自己的flip插件。总共170行。

    $.define("flip", "fx", function(){
        var flip = {
            begin: function() {
                var hyaline =  (!"1"[0] ? "#123456" : "transparent")//透明色,IE6不支持透明,因此要使用滤镜hack一下
                return {//初始化属性
                    hyaline: hyaline,
                    backgroundColor: hyaline,
                    fontSize:0,
                    lineHeight:0,
                    borderTopWidth:0,
                    borderLeftWidth:0,
                    borderRightWidth:0,
                    borderBottomWidth:0,
                    borderTopColor: hyaline,
                    borderBottomColor: hyaline,
                    borderLeftColor: hyaline,
                    borderRightColor: hyaline,
                    background: "none",
                    borderStyle: 'solid',
                    height:0,
                    0
                };
            },
            horizontal: function( obj ){
                var waist = obj.height /100 *25;
                var begin = flip.begin();
                begin.width= obj.width;//将初始属性克隆成三份,并逐渐改变它们
                return {
                    hyaline: begin.hyaline,
                    begin: begin,
                    middle: {
                        borderTopWidth: 0,
                        borderBottomWidth: 0,
                        borderLeftWidth: waist,
                        borderRightWidth: waist,
                        borderTopColor: "#999",
                        borderBottomColor:"#999",
                        top:  obj.top + (obj.height/2),//向上移
                        left: obj.left - waist//向左移
                    },
                    end: {
                        borderBottomWidth: 0,
                        borderTopWidth: 0,
                        borderLeftWidth: 0,
                        borderRightWidth: 0,
                        borderTopColor: begin.hyaline,
                        borderBottomColor: begin.hyaline,
                        top: obj.top,
                        left: obj.left
                    }
                };
            },
            vertical:  function ( obj ) {
                var waist = obj.height/100 * 25;
                var begin =  flip.begin();
                begin.height = obj.height;
                return {
                    hyaline: begin.hyaline,
                    begin : begin,
                    middle : {
                        borderTopWidth: waist,
                        borderBottomWidth: waist,
                        borderLeftWidth: 0,
                        borderRightWidth: 0,
                        borderLeftColor: "#999",
                        borderRightColor: "#999",
                        top: obj.top-waist,
                        left: obj.left+ (obj.width/2)
                    },
                    end: {
                        borderTopWidth: 0,
                        borderLeftWidth: 0,
                        borderRightWidth: 0,
                        borderBottomWidth: 0,
                        borderLeftColor: begin.hyaline,
                        borderRightColor: begin.hyaline,
                        top: obj.top,
                        left: obj.left
                    }
                };
            }
        }
        var dirMap = {
            t: "Top",
            b: "Bottom",
            l: "Left",
            r: "Right"
        }
        function getDirOption( obj, dir, orientation ){
            var result = flip[ orientation ]( obj ), arr = ["begin", "end"]
            dir.replace( $.rword, function( who ){
                var which = arr.shift();
                result[ which ]["border"+ who + "Width"] = obj[ orientation === "horizontal" ? "height" : "width"];
                result[ which ]["border"+ who + "Color"] = obj[which + "Bgc"];
            });
            return result;
        }
        //hash 中的主要参数 beginBgc endBgc before after frame, direction
        $.fn.flip = function(duration, hash){//并不是原对象进行动画,而是其克隆进行动画
            var props =  hash || duration || {}
            if(typeof duration === "function"){// fx(obj fn)
                hash = duration;               // fx(obj, 500, fn)
                duration = 500;
            }
            if(typeof hash === "function"){   //  fx(obj, num, fn)
                props.after = hash;           //  fx(obj, num, {after: fn})
            }
            var direction = props.direction || "tb";
            direction = dirMap[ direction.charAt(0) ] + ","+dirMap[ direction.charAt(1) ]
            duration = Math.floor( duration / 2 );
            var orientation = direction.charAt(1) === "o" ?  "horizontal" : "vertical" ;
            return this.each(function(){
                var $this = $(this);
                if($this.data('fliping')){
                    return false;
                }
                $this.data("fliping", 1);
                //取得原有对象中的有用的信息
                var message = {
                     $this.width(),
                    height: $this.height(),
                    beginBgc: hash.beginBgc || $this.css("bgc"),
                    endBgc: hash.endBgc || "#999",
                    top: $this.offset().top,
                    left: $this.offset().left
                };
                //添加替身
                var $clone = $this.css("visibility","hidden")
                .clone(true)
                .data('fliping',1)
                .appendTo("body")
                .html("")
                .css({
                    visibility: "visible",
                    position: "absolute",
                    left: message.left,
                    top: message.top,
                    margin: 0,
                    zIndex: 9999,
                    boxShadow:"0px 0px 0px #000"
                });
                var dirOption = getDirOption( message, direction, orientation);
                if(!"1"[0]){//fuck IE6
                    dirOption.begin.filter = "chroma(color=" + dirOption.hyaline + ")";
                }
                var middle = dirOption.middle, end = dirOption.end, self = this;
                //绑定回调
                middle.before = function( clone, prop, fx ){
                    if(typeof props.before === "function" ){
                        props.before.call( self, clone, prop, fx );
                    }
                }
                middle.frame = end.frame = function( clone, prop, fx ){
                    if(typeof props.frame === "function" ){
                        props.frame.call( self, clone, prop, fx );
                    }
                }
                end.after = function( clone, prop, fx){
                    $this.css("visibility", "visible").removeData('fliping');
                    $clone.remove();
                    if(typeof props.after === "function" ){
                        props.after.call( self, clone, prop, fx );
                    }
                }
                $clone.css( dirOption.begin ).fx( duration, middle).fx( duration, dirOption.end );
            })
        }
    })
    // 2012.2.19 发布
    

    下面就是完整例子:

    IE下如果报错,请它刷新页面,再不行,下载回来看。

    更详细的使用方法请到github,看它的文档

  • 相关阅读:
    [Unity工具]json查看工具02:获取Console窗口中的内容
    [Unity工具]json查看工具01:TreeView
    [Unity优化]包体积01:查找资源依赖
    大数据学习day21-----spark04------1. 广播变量 2. RDD中的cache 3.RDD的checkpoint方法 4. 计算学科最受欢迎老师TopN
    大数据学习day20-----spark03-----RDD编程实战案例(1 计算订单分类成交金额,2 将订单信息关联分类信息,并将这些数据存入Hbase中,3 使用Spark读取日志文件,根据Ip地址,查询地址对应的位置信息
    大数据学习day19-----spark02-------0 零碎知识点(分区,分区和分区器的区别) 1. RDD的使用(RDD的概念,特点,创建rdd的方式以及常见rdd的算子) 2.Spark中的一些重要概念
    大数据学习day18----第三阶段spark01--------0.前言(分布式运算框架的核心思想,MR与Spark的比较,spark可以怎么运行,spark提交到spark集群的方式)1. spark(standalone模式)的安装 2. Spark各个角色的功能 3.SparkShell的使用,spark编程入门(wordcount案例)
    大数据学习day17------第三阶段-----scala05------1.Akka RPC通信案例改造和部署在多台机器上 2. 柯里化方法 3. 隐式转换 4 scala的泛型
    大数据学习day16------第三阶段-----scala04--------1. 模式匹配和样例类 2 Akka通信框架
    大数据学习day15----第三阶段----scala03--------1.函数(“_”的使用, 函数和方法的区别)2. 数组和集合常用的方法(迭代器,并行集合) 3. 深度理解函数 4 练习(用java实现类似Scala函数式编程的功能(不能使用Lambda表达式))
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/2360428.html
Copyright © 2011-2022 走看看