<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    http://www.tkk7.com/ebecket 返還網
    隨筆-140  評論-11  文章-131  trackbacks-0
     1 放大倍數設置
     2 透明度設置
     3 反轉特效
     4 放大圖片層的大小自定義
     5 鼠標層的大小自定義
     6 ie6下select遮蓋問題
     7 光標樣式自定義
     8 zIndex設置

     

    簡單初始化方法舉例

    new flower.init("Demo","mag");
    new flower.init("Demo1","mag1",{
          max:3,zoomType:false,zoomWidth:200,zoomHeight:200,iframe:true,zIndex:666,cursor:"row-resize"
    });


     代碼講解

     defaultConfig={
            
    /**
             * 放大鏡的倍數
             * @type Number
             
    */
            max:
    3,

            
    /**
             * *放大鏡鼠標移動層的透明度
             * @type Number
             
    */
            opacity:
    0.5,

            
    /**顯示效果 false為默認,true為反色效果
             * @type Boolean
             
    */
            zoomType:
    false,

            
    /**顯示動畫
             * @type String
             
    */
            showEffect:
    'fadein',

            
    /**放大層的寬度
             * @type Number
             
    */
            zoomWidth:
    'auto',

            
    /**放大層的高度
             * @type Number
             
    */
            zoomHeight:
    'auto',
            
            
    /**鼠標層的寬度
             * @type Number
             
    */
            tipsWidth:
    'auto',
            
            
    /**鼠標層的高度
             * @type Number
             
    */
            tipsHeight:
    'auto',
            
            
    /**iframe遮蓋select
             * @type Boolean
             
    */
            iframe:
    false,
            
            
    /**iframe zIndex
             * @type Number
             
    */
            zIndex:
    999,
            
            
    /**光標樣式
             * @type String
             
    */
            cursor:
    "auto"
         };

    組件默認的參數配置,包括放大倍數,寬度,高度,透明度等的設置

     

    2 定義屬性

     namespace.init=function(content,mag,config){
            
    /**
             * 原始圖片容器
             * @type HTMLElement
             
    */
            
    this.content=D.get(content);

            
    /**
             * 放大圖片容器
             * @type HTMLElement
             
    */
            
    this.mag=D.get(mag);

            
    /**
             * 原始圖片
             * @type HTMLElement
             
    */
            
    this.imgsource=this.content.getElementsByTagName("img")[0];

            
    /**
             * 放大圖片
             * @type HTMLElement
             
    */
            
    this.img=this.mag.getElementsByTagName("img")[0];

            
    /**
             * 鼠標layer
             * @type HTMLElement
             
    */
            
    this.tips=this.content.getElementsByTagName("div")[0];

            
    /**
             * 配置參數
             * @type this.tipsect
             
    */
            
    this.config=L.merge(defaultConfig,config||{});

            
    /*初始化*/
            
    this._init();
         };

    init函數接受三個實參 原圖的容器id,和放大后的圖片容器id和配置參數 (裝firebug的同學可以看下代碼結構)

    this.config=L.merge(defaultConfig,config||{});

    這句話是后面的對象的屬性覆蓋前面的對象的屬性,并返回

    this.config=L.merge({"a":"aa"},{"a":"bb"});

    此時的this.config.a == "bb"

    config||{}

    如果config不存在,則返回空的對象自變量

     

    原型初始化方法

    代碼
    _init:function(){
                
    var self=this;

                
    /*賦值src給大圖*/
                
    this.img.src=this.imgsource.src;

                
    /*get邊框長度*/
                
    this.borderwidth=this.imgsource.offsetWidth - this.imgsource.clientWidth;

                
    /**
                 * 設置大圖片的寬度和高度 (X倍數)
                 * 設置大圖容器的寬高和位置
                 * 設置鼠標跟隨層的寬高和透明度
                 
    */
                
                
    this.pi=(this.config.zoomWidth!='auto'?this.config.zoomWidth/this.imgsource.offsetWidth:1)
                this.pi2=(this.config.zoomHeight!='auto'?this.config.zoomHeight/this.imgsource.offsetHeight:1)

                
    this._css(this.img,{
                    
    'position':'absolute',
                    
    'width':(this.config.zoomWidth!='auto' ?this.imgsource.offsetWidth*this.config.max*this.pi:this.imgsource.offsetWidth*this.config.max)+"px",
                    
    'height':(this.config.zoomHeight!='auto' ?this.imgsource.offsetHeight*this.config.max*this.pi2:this.imgsource.offsetHeight*this.config.max)+"px"
                })._css(
    this.mag,{
                    
    'width':(this.config.zoomWidth!='auto' ? this.config.zoomWidth:this.imgsource.offsetWidth)+"px",
                    
    'height':(this.config.zoomHeight!='auto'?this.config.zoomHeight:this.imgsource.offsetHeight)+"px",
                    
    'left':D.getX(this.content)+this.imgsource.offsetWidth+10+"px",
                    
    'top':this.content.offsetTop+"px",
                    
    'position' : 'absolute',
                    
    "zIndex":this.config.zIndex
                })._css(
    this.tips,{
                    
    'display':'',
                    
    'width':(this.config.tipsWidth!='auto' ? this.config.tipsWidth: parseInt(this.imgsource.offsetWidth / this.config.max)- this.borderwidth)+"px",    
                    
    'height' : (this.config.tipsHeight!='auto' ? this.config.tipsHeight: parseInt(this.imgsource.offsetHeight / this.config.max) - this.borderwidth )+ 'px',    
                    
    'opacity' : this.config.opacity
                })
            
                E.on(
    this.content,'mousemove',function(e){
                    self._css(self.mag,{
    "display":"block"})._css(self.tips,{"display":"block"})._move(e,self.tips)
                })

                
                E.on(
    this.content,'mouseout',function(e){
                    self._css(self.tips,{
    "display":"none"})._css(self.mag,{"display":"none"});
                })

                
    !!this.config.zoomType && E.on(self.tips,'mouseout',function(e){
                    self._css(self.imgsource,{
    "opacity":1});
                    self.tips.getElementsByTagName(
    "img")[0&& self.tips.removeChild(self.tips.getElementsByTagName("img")[0]);
                })

                
    if(ie6 && !!this.config.iframe){
                    
    this._createIframe(this.mag);
                }

                D.setStyle(
    this.content,"cursor",this.config.cursor);

            },


     組件的初始化原代碼

    默認鼠標跟隨的層和大圖是隱藏的 

    1.把圖片的鏈接賦值給將要放大顯示的圖片。

    2. 如有自定義zoomWidth或zoomHeight大小的時候,設置 this.pi 寬比 和this.pi2 高比 (為與實際圖片大小間的比值)

    3.設置大圖的寬度和高度

    4. 設置大圖容器的寬高和位置

    5.設置鼠標層的位置和寬高和透明度

    6 給原圖容器增加mousemove事件

    7. 給原圖容器增加mouseout事件

    8 反色特效后,還原透明度,并刪除用來實現效果的 Dom (在鼠標層結構內用appendChild一個img元素)

    9 ie6 創建iframe 用來遮擋的select。(默認情況下在無iframe的時候,ie6會被select擋住,無法用zIndex來修正 )

    10 設置光標樣式

     

    style設置的方法

    _css:function(el,json){
                
    for(var s in json){
                    D.setStyle(el,s,json[s]);
                }
            
    return this;
        },

    Yui有提供自己的 設置Dom樣式的方法 D.setStyle(dom,style屬性名,屬性的值);

    用 for (var s in json) 來遍歷 json對象的所有屬性

    return this; 常用的鏈式調用寫法  // this._css(/**/)._css(/**/) ._css(/**/) ……

     

    核心mousemove事件代碼

    _move:function(e,tips){
                
    var point=E.getXY(e);
                
    /**
                 * 提示層位置
                 * 大圖顯示位置
                 
    */
                
    this._css(tips,{
                    
    'top' : Math.min(Math.max(point[1- this.content.offsetTop-parseInt(tips.offsetHeight)/2 ,0),this.content.offsetHeight - tips.offsetHeight) + 'px',
                    'left' : Math.min(Math.max(point[0- this.content.offsetLeft-parseInt(tips.offsetWidth)/2 ,0),this.content.offsetWidth - tips.offsetWidth) + 'px'
                })._css(this.img,{
                    
    'top':-(parseInt(tips.style.top) * this.config.max *this.pi2)  + 'px',
                    
    'left' : - (parseInt(tips.style.left) * this.config.max *this.pi) + 'px'
                });

                
    /**
                 * 反色效果
                 
    */
                
    if(!!this.config.zoomType){
                    
    if(!tips.getElementsByTagName("img").length){
                        
    var imgs=document.createElement("img");
                        imgs.id
    ='temp';
                        imgs.src
    =this.imgsource.src;
                        
    this._css(imgs,{
                            
    'width':this.imgsource.offsetWidth+"px",
                            
    'height':this.imgsource.offsetHeight+"px",
                            
    'position':'absolute'
                        });
                        tips.appendChild(imgs);
                        
    this.imgs=imgs;
                    }
                
                    
    this._css(this.imgsource,{
                        
    "opacity":0.2
                    })._css(
    this.tips,{
                        
    "opacity":1,
                        
    "visibility":"visible"
                    })._css(D.get(
    "temp"),{
                        
    'top':-(parseInt(tips.style.top))+"px",
                        
    'left':-(parseInt(tips.style.left))+"px"
                    })
                }
            },

    提示層位置的移動 鼠標位置X軸 - this.offsetLeft - 鼠標框寬度/2

    并用Math.max和Math.min,不讓鼠標框超出tuxiang

    大圖位置的移動=小圖的位置 X 放大倍數 X 寬比(默認為1)

    反色效果是在jquery的一個插件上看到的 沒有看他的代碼 看了下他dom結構 應該和我這種實現方式是一樣的

    設置原圖的透明度為0.2 這樣就變灰色了 然后設置鼠標層透明為1,也就是不透明.層內是一個圖片 和 imgsource的地址是一樣的

    這圖片的父元素position也是absolute,所以我們要實時設置top和left值來定位鼠標層的圖片

     

    創建iframe

    _createIframe:function(el){
                
    var layer = document.createElement('iframe');
                layer.tabIndex = '-1';
                layer.src = 'javascript:false;';
                el.appendChild(layer);
                
    this._css(layer,{
                    
    "width":(this.config.zoomWidth!='auto' ? this.config.zoomWidth:this.imgsource.offsetWidth)+"px",
                    
    "height":(this.config.zoomHeight!='auto'?this.config.zoomHeight:this.imgsource.offsetHeight)+"px",
                    
    "zIndex":this.config.zIndex
                })
            }

    iframe元素的寬高和zIndex的設置,配置參數設置iframe:true并在ie6下 才會創建,在其他瀏覽器下設置true也不會創建,因為沒有必要

     

     

     代碼改進中

    1 增加特效的插件機制
    2 優化設定寬高值表達式的代碼 感覺太長太臃腫
    3 增加圖片預載
    4 增加回調函數接口
    5 增加className,讓用戶可自定義
    6 等等(...)


    地址打包下載 :放大鏡

    posted on 2010-03-31 09:23 becket_zheng 閱讀(320) 評論(0)  編輯  收藏 所屬分類: C#
    主站蜘蛛池模板: 大桥未久亚洲无av码在线 | 色片在线免费观看| 国产成人免费在线| 一个人看www在线高清免费看| 成年美女黄网站18禁免费 | 在线观看的免费网站| 亚洲熟女一区二区三区| 国产免费人视频在线观看免费| 免费国产高清视频| 亚洲中文久久精品无码| 亚洲激情视频在线观看| 亚洲av无码国产综合专区| 亚洲av成人一区二区三区观看在线| 男人免费视频一区二区在线观看| 国产一级黄片儿免费看| 四虎在线成人免费网站| 女人毛片a级大学毛片免费| 亚洲国产一区二区视频网站| 国产AV无码专区亚洲AVJULIA| 亚洲最新中文字幕| 日韩色视频一区二区三区亚洲 | 亚洲国产成人99精品激情在线| 国产精品成人亚洲| 久久免费视频99| 久久电影网午夜鲁丝片免费| 亚洲一级黄色视频| 亚洲另类自拍丝袜第1页| 羞羞视频网站免费入口| 99精品在线免费观看| 日本特黄特色免费大片| 亚洲日本一区二区三区在线| 久久精品国产亚洲AV忘忧草18| 免费一级黄色毛片| 在线电影你懂的亚洲| 国产亚洲美女精品久久久久| 国产白丝无码免费视频| 国产做床爱无遮挡免费视频| 亚洲天天做日日做天天欢毛片| 国产亚洲精品美女久久久久| 99re6免费视频| 亚洲国产人成中文幕一级二级|