四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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

在上個(gè)隨筆中貼出了效果庫的整體框架,和一個(gè)簡(jiǎn)單的opacity插件. 今天這個(gè)隨筆主要是擴(kuò)展其他常用
效果插件,畢竟框架只能是個(gè)空殼,內(nèi)容還是要自己充實(shí)。
如果看過了我上篇的實(shí)現(xiàn)細(xì)節(jié),這里就不多說廢話了,來段代碼先:
復(fù)制代碼 代碼如下:
/**//****************************************************/ 
// 移動(dòng), 這里是move to  就是移動(dòng)到 x,y 當(dāng)然,大家也可以再擴(kuò)展一個(gè)move by  移動(dòng)x個(gè)象素 
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樣式設(shè)置背景為 #ffffff格式,但程序取到的是 rgb(255,255,255)格式, 這里把他轉(zhuǎn)化為 #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() 

/**//****************************************************/ 
/**//****************************************************/ 
// 透明度,這個(gè)上個(gè)貼過了   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傳進(jìn)來自定義函數(shù)都可以
通過effect.setting來獲取element最初的設(shè)置。 在很多場(chǎng)合,我們需要在 options 中傳一個(gè) onComplete
函數(shù)進(jìn)來, 用來在效果執(zhí)行完畢后,打掃戰(zhàn)場(chǎng),恢復(fù)一些設(shè)置。
這些效果是可以重疊的,大家可以看看下面我寫的例子。
寫了十來個(gè)例子,應(yīng)該很詳細(xì)了。
完整的,可調(diào)試代碼和例子如下:

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

JavaScript技術(shù)如何寫一個(gè)通用的JavaScript效果庫!(2/2),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 蚀电影| 洪熙| 韩红个人资料| 日本电影芋虫| 夜魔3| 来势凶猛| 洛城僵尸| 蒋祖曼| 宝悦| 惊涛| 即便如此我依然爱着我的老婆| 美国伦理三颗熟樱桃| 三年片电影| 婚变电视剧免费观看| 大幻术师| 每周食品安全排查治理报告表| 肮脏性感的人| 忏悔三昧全文及回向文| 恰纳卡莱之战完整版在线观看| 傅首尔个人资料| 条件概率经典例题| bo妞| 田中敦子| 北京卫视今日播出节目表| 昭君出塞简谱| 赖小子| 疯狂72小时演员表| 雳剑 电视剧演员表| 祖卡尔| 滑胎最凶的食物孕早期| 美国派7| 黎小军| 罗斯福游戏| busty buffy| 无内裤全透明柔术视频| 少爷和我短剧| 我的抗战| 刘烨主演的电视剧| 舞法天女朵法拉演员表| 鼻子旁边长痘是什么原因造成的| 郑书允的10部作品|