user3176413
user3176413

Reputation: 29

I am a beginner in jQuery, please help me to understand this code

what does this function do?

 function topRise() {
        $(".topRise").animate({
            top: "-900px"
        }, 25000, topSet);
 };

Upvotes: 1

Views: 201

Answers (5)

Jai
Jai

Reputation: 74738

what does this function do?

function topRise() {
        $(".topRise").animate({
            top: "-900px"
        }, 25000, topSet);
 };

See your function has a jQuery selector and a method named .animate() bound on it.

so get it line by line:

  1. $(".topRise") is the selector which are elements with class name topRise.
  2. .animate() is used to animate css properties of elements.
  3. top:"-900px" here your element should be animate back to top.
  4. 25000 is the time to take to perform animation.
  5. topSet is a callback function which is getting called when animation ends.

Upvotes: 3

Scott
Scott

Reputation: 1922

jQuery selects the appropriate DOM element, in this case the element with class 'topRise':

$(."topRise")

Calls the jQuery animate() function, supplying some CSS properties to be set:

{top: "-900px"}

the duration of the animation, in milliseconds:

25000

the callback function which is called on completion

topSet

putting it all together:

function topRise() {
        $(".topRise").animate({
            top: "-900px"
        }, 25000, topSet);
 };

More information on jQuery animate and jQuery selectors

Upvotes: 4

Juned Lanja
Juned Lanja

Reputation: 1474

it will set css property top to -900px for tags those having class .topRise by running animation for 25000 millisecond then it will call topSet which is a callback function

Please look here for more info : http://api.jquery.com/animate/

Upvotes: 2

Guruprasad J Rao
Guruprasad J Rao

Reputation: 29683

When you call topRise() anywhere in js it will animate/move the element/s with class named topRise and the movement will happen to -900px to top and this will happen within a span of 25000 milliseconds i.e. 25 seconds. the callback topSet is a function that gets executed once 25 seconds of animation gets completed

Upvotes: 8

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93571

function topRise() {
        $(".topRise").animate({
            top: "-900px"
        }, 25000, topSet);
 };

It animates the top property of any elements with class="topRise" to a value of "-900px" over 25000 milliseconds (25 seconds) i.e. it moves them up, then it calls another function called topSet when complete.

Upvotes: 5

Related Questions