我想要創建的想法是:我有一些div作爲觸發器,當我將鼠標放在這些div上時,它們的數據將顯示在特定的div中(右側接近div),並且當我將鼠標移出默認值數據將顯示,並且每次都會出現淡入淡出效果。下面是我已經儘量做到如何在mouseover上創建javascript或css fadeInDown?
<style type="text/css">
.content {
margin-left: 200px;
border: 1px solid;
height : 0;
opacity : 0;
transition : opacity .3s ease, height .3s ease;
-webkit-transition : opacity .3s ease, height .3s ease;
-moz-transition : opacity .3s ease, height .3s ease;
position: absolute;
}
.content.fade-in-down {
opacity : 1;
height : 100px;
}
.trigger {
width: 100px;
height: 100px;
background-color: #333;
margin-bottom: 20px;
}
</style>
<script>
function show(id) {
document.getElementById("default").classList.remove("fade-in-down");
setTimeout(function(){
var el = document.getElementById(id);
el.classList.add("fade-in-down");
}, 500);
}
function hide(id) {
var el = document.getElementById(id);
el.classList.remove("fade-in-down");
setTimeout(function(){
document.getElementById("default").classList.add("fade-in-down");
}, 500);
}
window.onload = function(e) {
var el = document.getElementById("default");
el.classList.add("fade-in-down");
};
</script>
<div style="display: block; width: 100%">
<!--These Three div are the trigger-->
<div style="float: left;">
<div onMouseOver="show('div1');" onMouseOut="hide('div1')" class="trigger"></div>
<div onMouseOver="show('div2');" onMouseOut="hide('div2')" class="trigger"></div>
<div onMouseOver="show('div3');" onMouseOut="hide('div3')" class="trigger"></div>
</div>
<!--These are the data-->
<div id="default" class="content" style="position: absolute;">This is default</div>
<div id="div1" class="content">Div 1 Content</div>
<div id="div2" class="content">Div 2 Content</div>
<div id="div3" class="content">Div 3 Content</div>
</div>
現在的問題是:在當我鼠標移到DIV1,DIV2或DIV3數據顯示,但以前的DIV數據也鑲上DIV顯示,看起來很亂。我用滑下這將是更好的,如果我可以使用fadeInDown效果,而不是向下滑動淡入
你想要一個純粹的JavaScript的解決方案,即沒有jQuery的呢? – Yass
如果它的工作比它會好的我 –