2011-12-07 86 views
0

尋找智慧:翻轉圖像按鈕Fancybox iFrame?

我已經嘗試使用html,javascript和jquery來創建翻轉圖像按鈕。無論我在添加href fancybox iframe彈出鏈接時如何創建滾動按鈕,它都會打開整個網頁以鏈接到該鏈接,而不是像創建彈出窗口一樣。

如果我只有一個沒有翻轉的圖像按鈕,彈出窗口工作得很好。有什麼我需要添加到fancybox JavaScript或fancybox與rollover不兼容嗎?

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      <html xmlns="http://www.w3.org/1999/xhtml"><head> 
       <title>TESTING</title> 

       <!-- rollover images using javascript --> 

      <script language="javascript" type="text/javascript"> 

      normal_image = new Image(); 
      normal_image.src = "images/contact_us_red.png"; 

      mouseover_image = new Image(); 
      mouseover_image.src = "images/contact_us_black.png"; 


      <!-- repeat the 4 lines above for any subsequent images. --> 

      function swap(){ 
      if (document.images){ 
      for (var x=0; 
      x<swap.arguments.length; 
      x+=2) { 
      document[swap.arguments[x]].src = eval(swap.arguments[x+1] + ".src"); 
      } 
      } 
      } 
      </script> 


      <!-- JAVASCRIPT FOR FANCYBOX --> 
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> 
       <script> 
        !window.jQuery && document.write('<script src="popup/jquery-1.4.3.min.js"><\/script>'); 
       </script> 
       <script type="text/javascript" src="popup/fancybox/jquery.mousewheel-3.0.4.pack.js"></script> 
       <script type="text/javascript" src="popup/fancybox/jquery.fancybox-1.3.4.pack.js"></script> 
       <link rel="stylesheet" type="text/css" href="popup/fancybox/jquery.fancybox-1.3.4.css" media="screen" /> 
       <link rel="stylesheet" href="style.css" /> 
       <script type="text/javascript"> 

       $(document).ready(function() { 
        $("img.rollover").hover(
         function() { this.src = this.src.replace("_off", "_on"); 
         }, 
         function() { this.src = this.src.replace("_on", "_off"); 

         }); 
         }); 


      $(document).ready(function() { 
         /* 
         * Examples - images 
         */ 

         $("a#example1").fancybox(); 

         $("a#example2").fancybox({ 
          'overlayShow' : false, 
          'transitionIn' : 'elastic', 
          'transitionOut' : 'elastic' 
         }); 

         $("a#example3").fancybox({ 
          'transitionIn' : 'none', 
          'transitionOut' : 'none'  
         }); 

         $("a#example4").fancybox({ 
          'opacity'  : true, 
          'overlayShow' : false, 
          'transitionIn' : 'elastic', 
          'transitionOut' : 'none' 
         }); 

         $("a#example5").fancybox(); 

         $("a#example6").fancybox({ 
          'titlePosition'  : 'outside', 
          'overlayColor'  : '#000', 
          'overlayOpacity' : 0.9 
         }); 

         $("a#example7").fancybox({ 
          'titlePosition' : 'inside' 
         }); 

         $("a#example8").fancybox({ 
          'titlePosition' : 'over' 
         }); 

         $("a[rel=example_group]").fancybox({ 
          'transitionIn'  : 'none', 
          'transitionOut'  : 'none', 
          'titlePosition'  : 'over', 
          'titleFormat'  : function(title, currentArray, currentIndex, currentOpts) { 
           return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + '/' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>'; 
          } 
         }); 

         /* 
         * Examples - various 
         */ 

         $("#various1").fancybox({ 
          'titlePosition'  : 'inside', 
          'transitionIn'  : 'none', 
          'transitionOut'  : 'none' 
         }); 

         $("#various2").fancybox(); 

         $("#various3").fancybox({ 
          'width'    : '75%', 
          'height'   : '75%', 
          'autoScale'   : false, 
          'transitionIn'  : 'none', 
          'transitionOut'  : 'none', 
          'type'    : 'iframe' 

         }); 

         $("#various4").fancybox({ 
          'padding'   : 0, 
          'autoScale'   : false, 
          'transitionIn'  : 'none', 
          'transitionOut'  : 'none' 
         }); 
        }); 
      function MM_swapImgRestore() { //v3.0 
       var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc; 
      } 
      function MM_preloadImages() { //v3.0 
       var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); 
       var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) 
       if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} 
      } 

      function MM_findObj(n, d) { //v4.01 
       var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { 
       d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} 
       if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; 
       for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
       if(!x && d.getElementById) x=d.getElementById(n); return x; 
      } 

      function MM_swapImage() { //v3.0 
       var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3) 
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];} 
      } 
       </script> 

      </head> 
      <body onload="MM_preloadImages('images/contact_us_red.png')"> 
       <!-- THIS LINK WORKS. --> 
      <p><a id="various3" href="Contact/templates/form.tpl.html"><img src="images/contact_us_red.png" width="108" height="36" /></a> 

      </p> 
      <p>&nbsp;</p> 


      <!-- HERE IS THE JAVA LINK THAT WONT WORK --> 
      <a id="various3" href="Contact/templates/form.tpl.html" onMouseOver="swap('name_of_img','normal_image')" onMouseOut="swap('name_of_img','mouseover_image')"><img name="name_of_img" src="images/contact_us_black.png" border="0"></a> 

      <p>&nbsp;</p> 

      <!-- HERE IS THE HTML LINK THAT WONT WORK --> 
      <a id="various3" href="Contact/templates/form.tpl.html" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image3','','images/contact_us_red.png',1)"><img src="images/contact_us_black.png" name="Image3" width="108" height="36" border="0" id="Image3" /></a> 

      </body> 
      </html> 
+0

是的,請提供代碼,html和你的javascript –

+0

最後得到了代碼發佈!謝謝您的幫助!! –

+0

我喜歡javascript,但我認爲翻轉應該是一個CSS的任務;) – JFK

回答

0

只需使用熱點和行爲。如果你使用的是Dreamweaver,你的生活將會100%簡單。