javascript放大圖片

來源:互聯網
上載者:User

核心代碼收集於網路(IE6,7,8,Firefox/3.6.11和TT4.8下測試通過).

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>無標題頁</title>
    <script type="text/javascript">
    function CreatePopup() {  
        var SetElementStyles = function( element, styleDict ) {  
            var style = element.style ;  
            for ( var styleName in styleDict )style[ styleName ] = styleDict[ styleName ] ;   
        }  
        var eDiv = document.createElement( 'div' );   
        SetElementStyles( eDiv, { 'position': 'absolute', 'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height': 0 + 'px', 'zIndex': 1000, 'display' : 'none', 'overflow' : 'hidden' } ) ;  
        eDiv.body = eDiv ;  
       var opened = false ;  
       var setOpened = function( b ) {  
           opened = b;   
       }  
       var getOpened = function() {  
           return opened ;   
       }  
       var getCoordinates = function( oElement ) {  
           var coordinates = {x:0,y:0} ;   
           while( oElement ) {  
               coordinates.x += oElement.offsetLeft ;  
               coordinates.y += oElement.offsetTop ;  
               oElement = oElement.offsetParent ;  
           }  
           return coordinates ;  
       }  
      return {
          htmlTxt : '',
          document : eDiv,
          isOpen : getOpened(),
          isShow : false,
          hide : function() {
              SetElementStyles( eDiv, { 'top': 0 + 'px', 'left': 0 + 'px', 'width': 0 + 'px', 'height': 0 + 'px', 'display' : 'none' } ) ;
              eDiv.innerHTML = '' ;
              this.isShow = false ;
          },
          show : function( iX, iY, iWidth, iHeight, oElement ) {
              if (!getOpened()) { document.body.appendChild( eDiv ) ; setOpened( true ) ; } ;
              this.htmlTxt = eDiv.innerHTML ;
              if (this.isShow) { this.hide() ; } ;
              eDiv.innerHTML = this.htmlTxt ;
              var coordinates = getCoordinates ( oElement ) ;
              eDiv.style.top = ( iX + coordinates.x ) + 'px' ;
              eDiv.style.left = ( iY + coordinates.y ) + 'px' ;
              eDiv.style.width = iWidth + 'px' ;
              eDiv.style.height = iHeight + 'px' ;
              eDiv.style.display = 'block' ;
              this.isShow = true ;
          }
      }  
   }
    var oPopup;//控製圖片的展示
    if (!window.createPopup) {  
        oPopup=CreatePopup();
    }
    else{
        oPopup = window.createPopup();
    }  
    function FillOutImage(imgUrl,eventTag) {    
        with (oPopup.document.body) {        
            style.backgroundColor = "lightyellow";        
            style.border = "solid black 1px";        
            innerHTML = "<img src='" + imgUrl + "' width='100%' height='100%' />";     
        }    
        var event = eventTag||window.event;  
        oPopup.show(event.clientX + 80, event.clientY+10, 300, 250);//表單的大小
    }
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <img src="imgages/bg_cm.jpg" border="0" width="100" height="100" onmousemove="FillOutImage('imgages/bg_cm.jpg',event)"  onmouseout="oPopup.hide();"  alt=""/>
    </div>
    <div id="divHere"></div>
    </form>
</body>
</html> 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.