Can someone explain this jQuery code?

Possible duplicate:
Can someone explain this jQuery code?

I posted this before, but I would like to clarify my question (and I cannot do this in the old thread).

The code:

$(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 is taken here: http://wilq32.googlepages.com/wilq32.rollimage222 , and there is a demo function (animation of image rotation - 3rd demo on the page).

What I need to explain:

  • I understand that the variable “rot” is declared there, but I can’t understand where the declaration ends ....

  • When a variable is used, it is used as rot [0], which means [0]? is it an array?

  • I have never seen the attachment used so, the original syntax

    $ ("selector"). bind (type, [data], fn);

What's happening? What are all commas and [] about?

  1. , script "X", "Y" . ( "" )?

!

+3
4

, ...

:

, , script "X", "Y" . ( "bind" )?

:

var x=$("#imagex"); //<-- image to be rotated
var y=$("#elemy"); //<-- element to be clicked
var angleOfRotation=45; //<-- angle of rotation

y.bind("click",function(){
  x[0].rotateAnimation(angleOfRotation);
});
+4

2 . , .

rot - jQuery, , .

rot[0] - DOM, #image3, ID-3.

bind, bind, , .

[foo, bar] foo bar. Curly braces {foo: "foo", bar: "bar" } - foo bar.

+2
  • . rot , rotate() ( $('#image3'), - jQuery ). rotate( next ) - , rotate().

  • , [0] - . rot[0] ( "0-" ) rot.

  • { maxAngle:25, minAngle:-55, bind: ... } " ", , maxAngle, minAngle bind. myObject ( , rotate()), , myObject.maxAngle, myObject.minAngle myObject.bind. bind , .

+1

, - :

var itemYouWannaRotate = $("#imageToRotate").rotate(0);
$("#TriggerElement").click(function(){
    itemYouWannaRotate[0].rotateAnimation(90);
});

, , .

0
source

Source: https://habr.com/ru/post/1725746/


All Articles