简体   繁体   English

JQuery.hover() 在 IE7 或每个版本 IE 的兼容模式下不起作用

[英]JQuery .hover() not working in IE7 or compatability mode for each version of IE

I'm building a menu that allows the user to hover over the given topic, and a menu drops down to reveal an array of different options.我正在构建一个菜单,允许用户在给定主题上 hover,并且菜单下拉以显示一系列不同的选项。

Everything works fine in Safari, Chrome, Firefox, Opera, IE9 - IE8 (non-compatability view), but IE7 is doing something weird.在 Safari、Chrome、Firefox、Opera、IE9 - IE8(非兼容性视图)中一切正常,但 IE7 做的很奇怪。

In HTML, my menu is built like this:在 HTML 中,我的菜单是这样构建的:

<div id="menu_container">
<div id="menu_collapse">
    <div id="menu">
        <div id="home_button">
            </div>
                <ul>
                    <li>Television</li>
                    <li>Radio</li>
                    <li>Get Involved</li>
                    <li>Non-Profit Services</li>
                    <li>Education</li>
                    <li>Donate</li>
                    <li>Extra</li>
                </ul>
            </div>
            <div id="search_menu">
                <div id="socialcons">
                    <img src="css/img/twitter.jpg">
                    <img src="css/img/facebook.jpg">
                </div>
                <input type="text" name="search">
                <button></button>
            </div>
        </div>
    </div>
</div>

My CSS looks like this:我的 CSS 看起来像这样:

#menu_container
{
clear:both;
float:left;
width:1000px;
}

#menu
{
float:left;
width:700px;
height:50px;
background-color:#654a6f;
}

#home_button
{
height:50px;
width:40px;
float:left;
background-image:url('img/home.jpg');
background-repeat:no-repeat;
}

#menu ul
{
background-color:#485860;
}

#menu li img
{
margin:0;
padding:0;
}

#menu li
{
float:left;
color:#ffffff;
line-height:50px;
padding-left:15px;
padding-right:15px;
text-shadow:1px 1px 2px #3e204d;
}

#menu li.active
{
background-image:url('img/menu_hover.jpg');
background-repeat:no-repeat;
background-position:bottom center;
}

#menu li:hover
{
background-image:url('img/menu_hover.jpg');
background-repeat:no-repeat;
background-position:bottom center;
}

#menu_collapse
{
position:absolute;
float:left;
width:1000px;
height:50px;
background-image:url('img/menu_collapse_bg.jpg');
background-repeat:repeat-x;
background-color:#ffffff;
z-index:99999;
}

#search_menu
{
height:40px;
width:295px;
padding-right:5px;
padding-top:10px;
float:right;
line-height:50px;
background-image:url('img/search_menu.jpg');
background-repeat:no-repeat;
}

#search_menu input
{
float:left;
width:140px;
}

#search_menu button
{
height:32px;
width:32px;
border:0;
outline:0;
float:left;
background-image:url('img/search.jpg');
}

#socialcons
{
height:32px;
width:75px;
float:left;
margin-left:20px;
margin-right:10px;
line-height:0;
}

#socialcons img
{
margin-left:3px;
}

And here is my JQuery, Javascript:这是我的 JQuery、Javascript:

$(document).ready(function() {
$('#menu li').mouseover(function() {
    $('.active').removeClass('active');
    $('#menu_collapse').animate({height:'210'}, 300);
    $('#menu li').mouseout(function() {
        $(this).addClass('active');
    });
});
    $('#menu_collapse').hover(function(){},function(){
        $('#menu_collapse').animate({height:'50'}, 300);
        $('.active').removeClass('active');
    }); 
});

In IE7, and all "compatible" modes with IE, the div #menu_collapsable animates back up when I hover of it, thus defeating the purpose of having it.在 IE7 以及与 IE 的所有“兼容”模式中,当我对它进行 hover 时,div #menu_collapsable 会进行动画备份,从而违背了拥有它的目的。

Help!!帮助!!

$(document).ready(function() {
    $('#menu li').hover(
        function(){
            $('.active').removeClass('active');
            $('#menu_collapse').animate({height:'210'}, 300);
        },
        function(){
            $(this).addClass('active');
        }
    );
    $('#menu_collapse').mouseleave(function(){
        $(this).animate({height:'50'}, 300);
        $('.active').removeClass('active');
    }); 
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM