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, width: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 = { width: $ 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,看它的文档。
如果您觉得此文有帮助,可以打赏点钱给我支付宝1669866773@qq.com ,或扫描二维码


机器瞎学/数据掩埋/模式混淆/人工智障/深度遗忘/神经掉线/计算机幻觉/专注单身二十五年
标签:
javascript
, mass
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2010-02-20 淘到三个有用Object标签
2010-02-20 判定对象是否为window
2010-02-20 语法高亮插件SyntaxHighlighter的使用教程