[英]Hovered item doesn't show hidden elements when it expands
My goal is to diplay hidden elements in a box that expands when hovered, but it doesn't work. 我的目标是将隐藏的元素显示在悬停时会扩展的框中,但不起作用。 Here's the code what i'm using.
这是我正在使用的代码。 I assume it's the problem in the javascript because I have not much knowledge coding with it.
我认为这是javascript中的问题,因为我没有太多的编码知识。
HTML: HTML:
<div class="jackpot-add">
<p><img src="img/clan-standard-header.png" class="img-circular-small" alt="user-avatar">text</p>
<div id="show-hide">
<img src="skins/skin.png" id="border-img" style="width: 100px; height: 100px;">
</div>
</div>
CSS: CSS:
.jackpot-add {
display: block;
background:#538fae;
width: auto;
height: 55px;
padding: 10px;
border-left: 10px solid #396379;
margin-bottom: 15px;
margin-top: 15px;
transition:height 1.6s;
-webkit-transition:height 1.6s;
}
.jackpot-add:hover{
height: 300px;
-webkit-transition: height 0.5s;
-moz-transition: height 0.5s;
-o-transition: height 0.5s;
-ms-transition: height 0.5s;
}
#show-hide{
visibility: hidden;
}
Javascript: Javascript:
var imageNode = document.getElementById('show-hide')
function MyFuncHover() {
imageNode.style.visibility = 'visible'
}
function MyFuncOut(event) {
if (event.target !== imageNode) {
imageNode.style.visibility= 'hidden'
}
}
document.getElementsByClass('jackpot-add').addEventListener('mouseover', MyFuncHover, true)
document.getElementsByClass('jackpot-add').addEventListener('mouseout', MyFuncOut, true)
Instead of using javascript, you can use pure css to show/hide on hover. 除了使用JavaScript,您还可以使用纯CSS在悬停时显示/隐藏。
https://jsfiddle.net/hbkdw8dj/4/ https://jsfiddle.net/hbkdw8dj/4/
#show-hide {display:none;}
.jackpot-add:hover #show-hide {display:initial;}
Updated with opacity instead of display:none. 更新为不透明而不是显示:无。
.jackpot-add:hover .show-hide {
opacity:1;
transition-delay: 0.5s;
}
I'm not exactly sure what you want to do, but I tried: http://jsfiddle.net/rooydv4m/1/ 我不确定您要做什么,但是我尝试过: http : //jsfiddle.net/rooydv4m/1/
You don't need any JavaScript at all, and it's probably better to use CSS. 您根本不需要任何JavaScript,使用CSS可能更好。
The reason your JavaScript didn't work is that you used 您的JavaScript无法使用的原因是您使用了
document.getElementsByClass('jackpot-add').addEventListener('mouseover', MyFuncHover, true)
And 和
document.getElementsByClass('jackpot-add')
returns an array of all elements with the class
name jackpot-add
. document.getElementsByClass('jackpot-add')
返回所有具有class
名称jackpot-add
元素的数组。
You should have used: 您应该使用过:
document.getElementsByClass('jackpot-add')[0].addEventListener('mouseover', MyFuncHover, true)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.