javascript - How do I make something (a string) appear after some seconds? - Stack Overflow

I just want to make the string "¿Where are you?" fade in after around 5 seconds after loading

I just want to make the string "¿Where are you?" fade in after around 5 seconds after loading the site. Is there is an easy way to do it? It made be obvious but I'm pretty new to this stuff. Thanks a lot

I just want to make the string "¿Where are you?" fade in after around 5 seconds after loading the site. Is there is an easy way to do it? It made be obvious but I'm pretty new to this stuff. Thanks a lot

Share edited Dec 16, 2010 at 1:26 Jonah 10.1k5 gold badges49 silver badges79 bronze badges asked Dec 16, 2010 at 1:21 lisovaccarolisovaccaro 34.1k99 gold badges271 silver badges423 bronze badges 1
  • 1 PHP won't do this, you need Javascript. – Jonah Commented Dec 16, 2010 at 1:26
Add a ment  | 

3 Answers 3

Reset to default 6

You'll need javascript for that, in particular, the jQuery javascript library will make it very easy to do.

You need to add this in your <head> section of the page:

<script type="text/javascript" src="http://code.jquery./jquery-1.4.4.js"></script>
<script type="text/javascript">
   $(document).ready(function () {
      setTimeout(function () {
         $("body").append("<p>¿Where are you?</p>").fadeIn();
      }, 5000);
   });
</script>

The first <script> loads the jQuery library which in this situation lets you easily run code after the document has loaded and has handy shortcuts for fading in elements. The second <script> is where you set a timer for 5000 milliseconds, after which you add some text to the document and fade it in.

That'll get you started, but you'll need to know javascript and jQuery to take this further...

you can use the setTimeout function in javascript to achieve this.

something like this:

setTimeout("alert('¿Where are you?')", 5000);

  • Using jQuery: Try a fadeIn bined with a delay,
  • or plain javascript:

    setTimeout("alert('Surprise!')", 5000);
    

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744923542a4601286.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信