简体   繁体   中英

How can I play an animation on page load in jQuery so that it plays for index.php but not e.g. other_page.php

I want to play an animation on page load but only for my index.php and not for every other page of my website.

Is there something like this for jQuery:

$('index.php').ready(function());

?

If not how can I achieve the desired effect?

Just put your jQuery code in index.php page only using any of the following jquery load functions.

$(window).load(function(){...});

or

$(document).ready(function(){...});

or

$('body').onload(function(){...});

by this your animation will run only on index.php page and not any other page.

Hope this will solve your problem.

You can check the url with Javascript and then fire your function to play

if(
window.location.href=="address to check"
)
 your_function();
{
/* some code to load */
}else{
document.write('<div>testing my super loaded div code sample</div>')
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM