如何在HTML中加载div时淡出淡出

时间:2012-04-23 05:34:34

标签: javascript html

我有代码可以在点击按钮时淡出淡出但是我希望在文本加载时它应该淡入或淡化如何执行此操作而不是按钮单击

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Fading JavaScript Example</title>
 <link rel="stylesheet" type="text/css" href="style.css" />
 <script type="text/javascript" src="script.js"></script>
 </head>
 <body>
 <div id="wrapper">
<div id="fade">Fading JavaScript Example</div>
<div id="buttons">
    <div class="button" onclick="fadeEffect.init('fade', 1)">Fade In</div>
    <div class="button floatright" onclick="fadeEffect.init('fade', 0)">Fade Out</div>
</div>
<p>For more information visit <a href="http://www.leigeber.com">leigeber.com</a>.       </p>
  </div>
  </body>
 </html>

1 个答案:

答案 0 :(得分:0)

您可以使用<body onload="">

...
</head>
<body onload="fadeEffect.init('fade', 1)">
...

Read more here

或与jQuery $(document).ready();相同:

...
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {

    $('#fademein').fadeIn( 1000 );
});
</script>
</head>
<body>
...
<span id="fademein" style="display: none">Will fade in smoothly</span>

Read more here