我正在尝试创建一个站点,您可以在其中单击菜单中的链接,然后菜单下方的 div平滑地向下移动,当它到达该位置时,文本应该出现在新的间隙中。
我目前正处于学习 js 的开始阶段,所以不要期望那么多。不知何故,动画无法正常工作,而使用 setInterval 我无法做到。
这是代码:
<!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=iso-8859-1" />
<style>
/* CSS Document */
#container{
border: 1px solid #339999;
width: 798px;
}
#top{
background-image:url(images/background1.jpg);
width: 800xp;
height: 289px;
background-repeat:no-repeat;
}
#bot{
background-image:url(images/background2.jpg);
width: 800xp;
height: 250px;
background-repeat:no-repeat;
margin-top:0px;
}
ul.menu{
list-style-type: none;
padding-left: 30px;
font-size:13pt;
font-family: FrizQuadrata, Calibri;
color: #339999;
}
ul.menu li{
display:inline;
}
#text{
}
#footer{
font-size: 16px;
color: white;
font-family: FrizQuadrata, Calibri;
position: relative;
top: 150px;
left: 450px;
}
.title{
font-size:48px;
color: #339999;
font-family: FrizQuadrata, Calibri;
}
.subtitle{
font-size:33px;
color: #339999;
font-family: FrizQuadrata, Calibri;
}
#logo{
position: relative;
top: 10px;
left: 500px;
}
ul li a{
text-decoration: none;
color: inherit;
}
#d0{
height:80px;
}
#d1{
height:80px;
}
#d2{
height:80px;
}
#d3{
height:80px;
}
</style>
<script type="text/javascript">
var finished = false;
var timeout = null;
function OpenSite(site, finished){
menu = document.getElementById(site);
bot = document.getElementById('bot');
marg = bot.style.marginTop;
sheight = menu.offsetHeight;
marg = marg.slice(0,-2);
intmarg = parseInt(marg, 10);
intheight = parseInt(sheight, 10);
bot.style.marginTop = intmarg + 2 + 'px';
if (intmarg > intheight) {
finished = true;
}
if(finished == false){
timeout = setTimeout('OpenSite(site, finished)', 500);
clearTimeOut(timeout)
}
}
</script>
</head>
<div id="container">
<div id="top">
<div id="logo">
<span class="title">INTERPRESA</span><br />
<span class="subtitle">Consulting GmbH</span>
</div>
</div>
<div id="text">
<ul class="menu">
<li><a href="javascript:OpenSite('d0', false)">Projektmanagement</a> </li>
<li><a href="javascript:OpenSite('d1', false)">Unternehmensberatung</a> </li>
<li><a href="javascript:OpenSite('d2', false)">Interimsmanagement</a> </li>
<li><a href="javascript:OpenSite('d3', false)">Finanzwesen</a></li>
</ul>
<div id="d0">
d0<br /><br /><br /><br />
</div>
<div id="d1">
d1<br /><br /><br /><br />
</div>
<div id="d2">
d2<br /><br /><br /><br />
</div>
<div id="d3">
d3<br /><br /><br /><br />
</div>
</div>
<div id="bot" style="margin-top:0px;">
<div id="footer">
<table cellpadding="3">
<tr>
<td>Schützenegg 956 ·</td>
<td>5728 Hontenschwil</td>
</tr>
<tr>
<td> Tel. 062 773 80 00 ·</td>
<td> Fax 062 773 80 05</td>
</tr>
<tr>
<td colspan="2">info@interpresa.ch</td>
</tr>
</table>
</div>
</div>
</div>
<body>
</body>
</html>