天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

如何寫一個通用的JavaScript效果庫!(2/2)

在上個隨筆中貼出了效果庫的整體框架,和一個簡單的opacity插件. 今天這個隨筆主要是擴展其他常用
效果插件,畢竟框架只能是個空殼,內容還是要自己充實。
如果看過了我上篇的實現細節,這里就不多說廢話了,來段代碼先:
復制代碼 代碼如下:
/**//****************************************************/ 
// 移動, 這里是move to  就是移動到 x,y 當然,大家也可以再擴展一個move by  移動x個象素 
Effect.Init.move=function(effect){   //初始化 
    if (effect.options.x!==undefined || effect.options.y!==undefined){         
        var pos=Position.cumulativeOffset(effect.element); 
        effect.setting.left       =pos[0]; 
        effect.setting.top          =pos[1]; 
        effect.setting.position =effect.element.style.position;      
        effect.element.style.position    ="absolute" 
        effect.options.x=(effect.options.x===undefined)?effect.setting.left:effect.options.x; 
        effect.options.y=(effect.options.y===undefined)?effect.setting.top :effect.options.y;                         
    } 

Effect.Fn.move=function(effect,pos){     //效果 
    if (effect.options.x===undefined && effect.options.y===undefined) return         
    effect.element.style.left=effect.setting.left + (effect.options.x-effect.setting.left) * pos +"px"; 
    effect.element.style.top =effect.setting.top  + (effect.options.y-effect.setting.top ) * pos +"px"; 

/**//****************************************************/ 

/**//****************************************************/ 
// zoom   by Go_Rush(阿舜) from http://ashun.cnblogs.com/ 
Effect.Init.zoom=function(effect){     
    effect.setting.zoom      =effect.element.style.zoom || 1; 
    // firefox 不支持 css的 zoom 用  改變 width,height的方式代替  
    if (effect.options.zoom!==undefined && navigator.userAgent.toLowerCase().indexOf('firefox') != -1){                     
        effect.options.w=effect.element.offsetWidth  * effect.options.zoom; 
        effect.options.h=effect.element.offsetHeight * effect.options.zoom;     
    } 

Effect.Fn.zoom=function(effect,pos){ 
    if (effect.options.zoom===undefined) return; 
    effect.element.style.zoom=effect.setting.zoom+(effect.options.zoom-effect.setting.zoom)*pos 

/**//****************************************************/ 
/**//****************************************************/ 
// size  同上,是 size to, 改變到指定大小 by Go_Rush(阿舜) from http://ashun.cnblogs.com/ 
Effect.Init.size=function(effect){ 
    if (effect.options.w!==undefined || effect.options.h!==undefined){ 
        effect.setting.overflow   =effect.element.style.overflow || 'visible'; 
        effect.setting.width      =effect.element.offsetWidth; 
        effect.setting.height      =effect.element.offsetHeight;  
        effect.element.style.overflow ="hidden"     
        effect.options.w=(effect.options.w===undefined)?effect.setting.width :effect.options.w; 
        effect.options.h=(effect.options.h===undefined)?effect.setting.height:effect.options.h;             
    } 

Effect.Fn.size=function(effect,pos){     
    if (effect.options.w===undefined && effect.options.h===undefined) return; 
    effect.element.style.width =effect.setting.width + (effect.options.w-effect.setting.width ) * pos +"px"; 
    effect.element.style.height=effect.setting.height+ (effect.options.h-effect.setting.height) * pos +"px"; 

/**//****************************************************/ 
/**//****************************************************/ 
// 背景色 by Go_Rush(阿舜) from http://ashun.cnblogs.com/ 
Effect.Init.bgcolor=function(effect){ 
    if (effect.options.bgcolor!==undefined && /^/#?[a-f0-9]{6}$/i.test(effect.options.bgcolor)){ 
        var color =effect.element.style.backgroundColor || "#ffffff"; 
        //FireFox 下,即使css樣式設置背景為 #ffffff格式,但程序取到的是 rgb(255,255,255)格式, 這里把他轉化為 #ffffff格式 
        if (/rgb/i.test(color)){               // "rgb(255, 0, 255)" 
            //var arr=color.replace(/[rgb/(/s/)]/gi,"").split(",") 
            var arr=eval(color.replace("rgb","new Array"))        
            color="#"+Number(arr[0]).toColorPart()+Number(arr[1]).toColorPart()+Number(arr[2]).toColorPart() 
        } 
        effect.setting.bgcolor=color 
    } 

Effect.Fn.bgcolor=function(effect,pos){     
    if (effect.options.bgcolor===undefined) return; 
    var c1=effect.setting.bgcolor,c2=effect.options.bgcolor 
    var arr1=[parseInt(c1.slice(1,3),16),parseInt(c1.slice(3,5),16),parseInt(c1.slice(5),16)] 
    var arr2=[parseInt(c2.slice(1,3),16),parseInt(c2.slice(3,5),16),parseInt(c2.slice(5),16)] 
    var r=Math.round(arr1[0]+(arr2[0]-arr1[0])*pos) 
    var g=Math.round(arr1[1]+(arr2[1]-arr1[1])*pos) 
    var b=Math.round(arr1[2]+(arr2[2]-arr1[2])*pos) 
    effect.element.style.backgroundColor="#"+r.toColorPart()+g.toColorPart()+b.toColorPart() 

/**//****************************************************/ 
/**//****************************************************/ 
// 透明度,這個上個貼過了   by Go_Rush(阿舜) from http://ashun.cnblogs.com/ 
Effect.Init.opacity=function(effect){ 
    if (effect.options.opacity===undefined) return; 
    effect.setting.opacity=Opacity(effect.element);     

Effect.Fn.opacity=function(effect,pos){ 
    if (effect.options.opacity===undefined) return; 
    Opacity(effect.element,effect.setting.opacity+(effect.options.opacity-effect.setting.opacity)*pos);     

/**//****************************************************/ 

這里 effect.setting 是非常有用而且非常重要的冬冬,所有的通過options傳進來自定義函數都可以
通過effect.setting來獲取element最初的設置。 在很多場合,我們需要在 options 中傳一個 onComplete
函數進來, 用來在效果執行完畢后,打掃戰場,恢復一些設置。
這些效果是可以重疊的,大家可以看看下面我寫的例子。
寫了十來個例子,應該很詳細了。
完整的,可調試代碼和例子如下:

[Ctrl+A 全選 注:如需引入外部Js需刷新才能執行]

JavaScript技術如何寫一個通用的JavaScript效果庫!(2/2),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 久久婷婷丁香五月色综合啪免费 | 寻找最美乡村教师颁奖晚会 | 久久伊人男人的天堂网站 | 轻点灬大ji巴太粗太双性高h | 日本一区不卡在线播放视频免费 | 男人桶女人j的视频在线观看 | 亚州精品永久观看视频 | 国产精品1区在线播放 | 国产伦精品一区二区三区 | 久久噜国产精品拍拍拍拍 | 先锋影音av最新资源 | 国产成人免费片在线观看 | 日本久久精品免视看国产成人 | 一本大道熟女人妻中文字幕在线 | 国产亚洲精品网站在线视频 | 99er热精品视频国产免费 | 长篇高h肉爽文丝袜 | 日日夜夜天天操 | 亚洲精品视频免费 | 办公室中文BD | 杨幂视频1分11未删减在线观看 | 九九大香尹人视频免费 | 国产精品99久久久久久人韩国 | 日日夜夜影院在线播放 | 99爱在线精品视频网站 | 国产成人久久精品AV | 5g天天影院天天看天天爽 | 亚洲乱亚洲乱妇13p 亚洲乱色视频在线观看 | 久久水蜜桃亚洲AV无码精品偷窥 | 色午夜日本高清视频www | 孕妇bbwbbwbbwbbw超清 | 美女医生深夜在家裸睡惨死 | 成人手机在线观看 | 99久久国产宗和精品1上映 | 最新亚洲人成网站在线影院 | 欧美极品尿交 | 欧美 亚洲 另类 综合网 | 亚洲精品国产在线观看 | WWW国产无套内射久久 | 青柠在线观看免费播放电影 | 果冻传媒9CM在线观看 |