有人可以解释一下这段 jQuery 代码吗?

发布于 2024-08-14 11:59:08 字数 545 浏览 3 评论 0原文

此代码取自 http://wilq32.googlepages.com/wilq32.rollimage222,并且应该为图像旋转设置动画。

我无法准确地弄清楚结构,以及如何训练它来做我想要的事情,例如 - 让 div X 在悬停时旋转 div Y (而不是旋转本身),或者添加其他功能,例如淡入淡出到动画。

$(document).ready(function()
  {
   var rot=$('#image3').rotate({maxAngle:25,minAngle:-55,
    bind:
     [
     {"mouseover":function(){rot[0].rotateAnimation(85);}},
     {"mouseout":function(){rot[0].rotateAnimation(-35);}}
     ]
   });
  });

提前致谢

This code is taken from http://wilq32.googlepages.com/wilq32.rollimage222, and is supposed to animate an image rotation.

I can't figure out the structure exactly, and how to train it to do what I want, for example - make div X rotate div Y on hover (instead of rotating itself), or adding other functions such as fade to the animation.

$(document).ready(function()
  {
   var rot=$('#image3').rotate({maxAngle:25,minAngle:-55,
    bind:
     [
     {"mouseover":function(){rot[0].rotateAnimation(85);}},
     {"mouseout":function(){rot[0].rotateAnimation(-35);}}
     ]
   });
  });

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久光 2024-08-21 11:59:08

这就是它的作用。
1) 等待页面加载 $(document).ready()
2) 将“rot”指定为等于 jQuery.rotate 对象。
3) 然后将该对象绑定到两个不同的事件,mouseover 和 mouseout。绑定意味着当这些事件触发时将执行该代码段。

鼠标悬停启动“rotateAnimation(85)”,鼠标悬停设置相同的功能-35。我猜它会反转它所看到的图像的旋转。

要将内容添加到轮换中,您可以这样做。

$(document).ready(function()
    {
            var rot=$('#image3').rotate({maxAngle:25,minAngle:-55,
            bind:
                    [
                            {"mouseover":function(){
                                 rot[0].rotateAnimation(85);}
                                 //insert awesome fades and effects here.
                            },
                            {"mouseout":function(){
                                 rot[0].rotateAnimation(-35);}
                                 // insert more cool fades and effects here.
                            }
                    ]
            });
    });

希望有帮助。

Here's what it does.
1) Waits for page load $(document).ready()
2) Assigns "rot" to equal a jQuery.rotate object.
3) This object is then bound to two different events, mouseover, and mouseout. Binding means that when those events trigger that piece of code will execute.

Mouseover starts "rotateAnimation(85)" and mouseout sets the same function -35. I'm guessing that it reverses the rotation of the image it's looking at.

To add things to the rotation, you could just do this.

$(document).ready(function()
    {
            var rot=$('#image3').rotate({maxAngle:25,minAngle:-55,
            bind:
                    [
                            {"mouseover":function(){
                                 rot[0].rotateAnimation(85);}
                                 //insert awesome fades and effects here.
                            },
                            {"mouseout":function(){
                                 rot[0].rotateAnimation(-35);}
                                 // insert more cool fades and effects here.
                            }
                    ]
            });
    });

Hope that helps.

尝蛊 2024-08-21 11:59:08

根据文档的绑定参数特定于rotateimage 对象。相反,我认为您只想在事件触发时使用旋转功能。

$(document).ready(function()
{
     $('#divY').mouseover( $('#divX').rotate({angle:35}) );
     $('#divY').mouseout( $('#divX').rotate({angle:-85}) ); 
});

The bind parameter according to the docs is specific to the rotateimage object. Instead I think you just want to use the rotate function when your event fires off.

$(document).ready(function()
{
     $('#divY').mouseover( $('#divX').rotate({angle:35}) );
     $('#divY').mouseout( $('#divX').rotate({angle:-85}) ); 
});
叹梦 2024-08-21 11:59:08

var rot 保存对 '#image3' 的引用。然后旋转限制为逆时针 55 度和顺时针 25 度。此时尚未发生任何用户可见的操作。 #image3 能够接收旋转动画命令。

然后绑定部分获取包含两个要绑定的对象的数组的内容。第一个绑定 #image3 的mouseover,这样它将触发对旋转 rot[0] 的调用,旋转本身就是顺时针 85 度。它不会移动 85 度,而是受到之前设置的限制,只能移动到 25 度。

第二个通过绑定mouseout 执行类似的操作,以便它将逆时针移动到 35 度,并且此移动不受 minAngle 限制。

var rot holds a reference to '#image3'. Then rotation is given limits of 55 degrees counter clockwise and 25 degrees clockwise. No user visible action has taken place at this point. #image3 is enabled to receive rotateAnimation commands.

Then the bind section takes the content of the array which holds two objects to bind. The first binds the mouseover of #image3 such that it will trigger a call to rotate rot[0], which is itself, 85 degrees clockwise. This does not travel 85 degrees, but is limited by the previous setting to only travel to 25 degrees.

The second does a similar thing with binding mouseout so that it will travel to 35 degrees counter clockwise and this travel is not limited by the minAngle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文