过渡效果仅在加载时运行一次,但在单击另一个选项卡时不起作用。每次更改选项卡时如何使其运行?
单击导航按钮时,内容应与过渡效果一起显示。HTML:
<body onload="setCurrent('home','home_content')">
<div id="wrap" class="center">
<div class="top">
<header class="left">
<h1><a href="#">transition</a></h1>
</header>
</div>
<div class="right">
<nav class="menu">
<ul>
<li><a class="" id="home" onclick="setCurrent('home','home_content')">Home</a></li>
<li><a class="" id="about" onclick="setCurrent('about','about_content')">About</a></li>
</ul>
</nav>
</div>
<div id="main">
<div id="place">
<div id="home_content" class="content">
<h3>Home</h3>
</div>
<div id="about_content" class="content">
<h3>About</h3>
</div>
</div>
</div>
</div>
CSS:
#place .content{
height: 1px;
padding: 20px;
margin: 0;
overflow: hidden;
transition:all 2s ease;
-moz-transition:all 2s ease; /* Firefox 4 */
-webkit-transition:all 2s ease; /* Safari and Chrome */
-o-transition:all 2s ease; /* Opera */
-ms-transition:all 2s ease; /* MS */
}
#place .hide{
display:none;
}
#place .expand{
display:block;
height:500px;
background-color:#f00;
}
JS:
function setCurrent(current,currentContent){
document.getElementById('home').className = 'none';
document.getElementById('about').className = 'none';
document.getElementById('home_content').classList.remove('expand');
document.getElementById('about_content').classList.remove('expand');
document.getElementById('home_content').classList.add('hide');
document.getElementById('about_content').classList.add('hide');
document.getElementById(current).className='current';
document.getElementById(currentContent).classList.remove('hide');
document.getElementById(currentContent).classList.add('expand');
return;
}