2012-04-26 70 views
1

我想使用jQuery旋轉圖像90度後點擊我的div。 它爲什麼不起作用?jQuery旋轉函數圖像選擇

這裏是我的HTML ...

<div class="class1"> 
    <div class="class2"> 
     <img id="whatever"> 
    </div> 
</div> 

..這是我的jQuery的;

jQuery(document).ready(function() { 
     jQuery(".class1").click(function() 
       { 
      jQuery(this).find('img').rotate({animateTo:-90}) 
       }); 
      }); 

如果有幫助, http://code.google.com/p/jqueryrotate/wiki/Examples

注:我需要的代碼,找到第一個圖像...不只是通過ID獲取圖像,然後將其旋轉。

+0

確定旋轉插件正在加載? Chrome控制檯或Firebug控制檯顯示什麼錯誤? – 2012-04-26 03:59:13

+0

我不確定如何檢查Chrome控制檯。 剛剛檢查過它。得到這個錯誤: 'Uncaught TypeError:Object [object Object]沒有方法'rotate'' – 2012-04-26 04:02:29

回答

2

根據@Abdullah Jibaly後,看看評論。我想你好想像

<script src="http://jqueryrotate.googlecode.com/svn/trunk/jQueryRotate.js"></script> 

而且這裏有一個例子,在第一圖像旋轉http://jsfiddle.net/oamiamgod/BeUBF/2/

+0

你是對的!我的錯誤...謝謝! – 2012-04-28 06:12:38

0

class名最前一頁字母不應該是一個數字,將其更改爲class1class2代替,並添加引號爲animateTo值:

<div class="class1"> 
    <div class="class2"> 
     <img id="whatever"> 
    </div> 
</div> 

    $(document).ready(function() { 
     $(".class1").click(function(){ 
      $(this).find('img').rotate({animateTo: "-90"}) 
     }); 
    }); 
+0

我只寫了'1'和'2'作爲例子。在我的劇本中,他們是文字。我雖然在這裏修正了它。 – 2012-04-26 03:54:26

+0

嘗試爲'animateTo'值添加引號。 – undefined 2012-04-26 03:56:56

+0

仍然無法正常工作....令人沮喪。 – 2012-04-26 03:58:57

0

嘗試

<div class="class1"> 
     <div class="class2"> 
      <img id="whatever"> 
     </div> 
    </div> 


jQuery(document).ready(function() { 
    jQuery(".class1").click(function() 
    { 
     $("#whatever").rotate(90); 
    }); 
}); 
1

代碼如下好,我想這個插件沒有被加載,或者在給定的上下文之外的東西出錯了。

爲了讓你可以使用第一IMG:

jQuery(this).find('img').first().rotate({animateTo:-90}) 
+0

如何檢查/發現問題? – 2012-04-26 04:01:47

+0

打開Chrome控制檯或Firebug控制檯,您應該會看到一個錯誤。 – 2012-04-26 04:02:23

+0

在Chrome中,使用Cmd + Option + i(mac)。 – 2012-04-26 04:03:58

1

//根據使用

<div class="class1"> 
    <div class="class2"> 
     <img src="https://www.google.com/images/srpr/logo3w.png"> 
     <img src="https://www.google.com/images/srpr/logo3w.png" > 
    </div> 
</div> 
     <button id='test'>click</button> 

<script> 
jQuery(document).ready(function() { 
    var setvalue=90; 
    jQuery("#test").click(function() { 
     jQuery('.class1').find('img').rotate({ 
      animateTo: setvalue 
     }); 
       setvalue=setvalue+90;   
    }); 
}); 
</script> 

https://code.google.com/p/jqueryrotate/wiki/Examples