0

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

 <!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>
4

1 回答 1

0

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

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

在这里阅读更多

或与 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>

在这里阅读更多

于 2012-04-23T05:43:07.350 回答