Mouseenter事件无效

时间:2014-10-15 02:20:11

标签: javascript jquery mouseenter

我在此功能中所做的是在您点击按钮时创建一个下拉菜单:

function toggleNavPanel(x){

    var panel = document.getElementById(x), navarrow = document.getElementById("navarrow"), maxH="300px";
    if(panel.style.height == maxH){
        panel.style.height = "0px";
        navarrow.innerHTML = "▾";
    } else {
        panel.style.height = maxH;
        navarrow.innerHTML = "▴";
    }
}

这很有效。但这不是我想要的。我想要的是有人能够鼠标悬停并弹出表格。

我所做的就是把它放到像这样的mouseenter函数中:

$('#story').mouseenter(function() {
    var panel = document.getElementById('dropdown'), maxH="300px";
        panel.style.height = "0px";

}).mouseleave(function() {
    var panel = document.getElementById('dropdown'), maxH="300px";
        panel.style.height = maxH;

});

这不起作用。实际的mouseenter事件永远不会执行,因为我已尝试过警报,但它也无法正常工作。

有人可以告诉我我做错了什么吗?下面是一些更相关的代码:

#story {
    position:relative;
    top: -20%;
    left: 0%;
    width: inherit;
    height: 25%;
    margin: 0 auto;
    margin-top: 5px;
    background-color: transparent;
    color: black;
    border-style: solid;
    border-width: 1px;
    border-color: #D8D8D8;  
 }
 #dropdownbutton {
    float:center;
    width:144px;
    height:46px;
    padding-top:16px;
    background:#F90;
}
#dropdown{
    position:absolute;
    height:0px;
    width:550px;
    background:#000;
    top:60px;
    left:160px;
    border-radius:0px 0px 8px 8px;
    overflow:hidden;
    z-index:10000;
    transition: height 0.3s linear 0s;
}

视图:

<div class="main">
    <div id="dropdownbutton">
        <button type="button" onclick="toggleNavPanel('dropdown')">Drop Down</button>
    </div>

    <div id="dropdown">
        <p>Working</p>
    </div>

故事元素的位置:

<div class="info_bar">
    <div id="story">Story</div>
    <div id="info">Info</div>
    <div id="content">Content</div>
</div>

1 个答案:

答案 0 :(得分:2)

基于讨论...

未包含jQuery库,代码未添加到dom ready handler