1

I'm trying to use jQuery to rotate an image 90 degrees upon click on my div. Why doesn't it work?

Here's my HTML ...

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

.. and here's my jQuery ;

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

If it helps, http://code.google.com/p/jqueryrotate/wiki/Examples

NOTE: I need the code to FIND the first image...not just get the image by id, then rotate it.

4

5 回答 5

2

根据@Abdullah Jibaly 的帖子并查看评论。我想你想念类似的东西

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

这是一个旋转第一张图片的例子http://jsfiddle.net/oamiamgod/BeUBF/2/

于 2012-04-26T04:17:23.450 回答
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

于 2014-06-19T17:02:27.020 回答
1

你的代码看起来很好,我猜插件没有被加载或者给定上下文之外的其他东西出错了。

要获得第一个 img,您可以使用:

jQuery(this).find('img').first().rotate({animateTo:-90})
于 2012-04-26T04:00:57.523 回答
0

fisrt letter of class name should not be a number, change them to class1 and class2 instead and add quotation marks for animateTo value:

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

  $(document).ready(function() {
       $(".class1").click(function(){
            $(this).find('img').rotate({animateTo: "-90"})
       });
  });
于 2012-04-26T03:52:29.787 回答
0

试试看

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


jQuery(document).ready(function() {
    jQuery(".class1").click(function()
    {
       $("#whatever").rotate(90);
    });
});
于 2012-04-26T03:55:10.810 回答