2013-05-05 159 views
0

我試圖創建一個簡單的效果作爲一個練習,基本上我想要的圖像時,我在它懸停改變和恢復時,我的鼠標從將無法​​正常工作?

 <!DOCTYPE html> 
    <html> 
     <head> 
      <title>Change pics on event</title> 
      <meta charset = "utf-8"> 
      <script src = "jsf/jquery-1.8.js"></script> 
      <link rel = "stylesheet" href = "talkpics.css"> 

     </head> 
     <body> 
      <div id = "pic"> 
       <img id = "sk" src = "tpi/skutch.jpg"> 
       <div id = "speech"> 
        <img src = "tpi/speech5.png"> 
       </div> 
      </div> 
      <script> 
       $(document).ready(function(){ 
         $("#sk").hover(function(){ 
         $(this).attr("src","tpi/skutch2.jpg"); 
          }, function(){ 
      $(this).attr("src", "tpi/skutch.jpg");   
           } 
       }); 
      }); 
      var sb = new Array(); 
       sb[0] = 'tpi/speech1.png'; 
       sb[1] = 'tpi/speech2.png'; 
       sb[2] = 'tpi/speech3.png'; 
       sb[3] = 'tpi/speech4.png'; 
       sb[4] = 'tpi/speech5.png'; 



      </script> 
     </body> 
    </html> 

數組是事物的一部分一樣,我要添加後來這是一個隨機的png講話泡泡..基本上我想讓圖像隨着隨機講話泡泡改變。但現在我的問題是要改變骷髏圖像。我已經在網上關注了tutes,並且已經給出了例子給出的代碼,但它不能用於skutch.jpg上的圖像。我不確定爲什麼任何幫助都很棒。

*{ 
padding:0px; 
margin:0px; 
border:none; 
} 

#pic{ 
height:500px; 
width:500px; 
margin-top:100px; 
margin-left:auto; 
margin-right:auto; 
} 

#sk{ 
position:relative; 
} 
#speech{ 
position:relative; 
top:-450px; 
left:-20px; 
} 
+2

對我來說很不錯。請把它撥弄。 – gillyspy 2013-05-05 07:44:55

回答

0

不知道,如果是這樣的問題,但你有一個額外的支架在這裏:

$(document).ready(function() { 
    $("#sk").hover(function() { 
     $(this).attr("src", "tpi/skutch2.jpg"); 
    }, function() { 
     $(this).attr("src", "tpi/skutch.jpg"); 
    //} <== Not needed, comment it out... 
    }); 
}); 
+0

thanx ..removed支架,但它仍然無法正常工作...嗯..代碼是整潔的我的Aptana文檔,但轉移到這裏奇怪。 – darthbeefer 2013-05-05 08:34:32

+0

適合我的工作:http://jsfiddle.net/HYSpa/ – 2013-05-05 08:45:02

+0

得到它的工作我有錯誤的文件擴展名爲我的第二張pic..duh ..現在的問題是,我的speech5.png是不可見的,當我懸停在所以我得到新的形象,但失去了PNN ..hmm..anyway我要去擺弄它一些..thanx幫助我的馬虎的錯誤 – darthbeefer 2013-05-05 09:36:57

0

如果格式化用更好的縮進你的代碼,你會看到你有一個額外}這不應該有,這是停止它的工作語法錯誤:

  $(document).ready(function() { 
       $("#sk").hover(function() { 
        $(this).attr("src", "tpi/skutch2.jpg"); 
       }, function() { 
        $(this).attr("src", "tpi/skutch.jpg"); 
       } // <-- remove this one 
       }); 
      }); 

還要注意,初始化您的數組一個更好的方式如下:

var sb = ['tpi/speech1.png', 
      'tpi/speech2.png', 
      'tpi/speech3.png', 
      'tpi/speech4.png', 
      'tpi/speech5.png']; 

的方式,你做到了工作但是當你不需要爲什麼打出來的所有sb[0] =部分?

+0

thanx ..我會記住,對於陣列 – darthbeefer 2013-05-05 08:35:10