Jquery 下拉菜单仅在 IE 上闪烁

发布于 2024-10-21 07:31:41 字数 1277 浏览 3 评论 0原文

我正在为一个新项目启动一个 Jquery 下拉菜单,它在 Google Chrome、Firefox、Safari 上按预期工作,但当然它在 Internet Explorer 上让我有些头痛。

事情是这样的, 请参阅此页 http://www.universidadedoingles.com.br/dev/index.ASP

将鼠标悬停在菜单“HOME”上时,会出现下拉菜单,当您将鼠标移到 IE 中的链接上时,您会看到一些背景闪烁,这在 Chrome 和 ETC 上不会发生。

这是我用来做 dd 菜单的 js coda。

<script type="text/javascript">
$(document).ready(function() {   
$("ul.mainmenu li.menuhome").mouseover(function(){
    $(".arrow-spacer").show(); //When mouse over ...
    //Following event is applied to the subnav itself (making height of subnav 150px)
    $(this).find('.submenu').show().animate({height: '150px', opacity:'1'},{queue:false, duration:300})     
});

$("ul.mainmenu li.menuhome").mouseout(function(){ //When mouse out ...
    //Following event is applied to the subnav itself (making height of subnav 0px)
    $(this).find('.submenu').hide().animate({height:'0px', opacity:'0'},{queue:false, duration:200})
});

//menu itembackground color animation           
$("li").hover(function() {
    $(this).animate();},
    function() {
        $(".arrow-spacer").hide();
    }); 
});
</script>

就是这样,我想这可能很简单,但已经过去几周了,我仍然无法让它工作。

多谢。

I am starting a Jquery drop down menu for a new project and it is working as expected on Google Chrome, Firefox, Safari but of course it is giving me some headache on Internet Explorer.

here's the thing,
See this page
http://www.universidadedoingles.com.br/dev/index.ASP

on mouse over the menu HOME, the drop down appers, when you move over the links in IE you see some flashes of the background, which doesn't happens on Chrome and ETC.

here's the js coda I am using to do the dd menu.

<script type="text/javascript">
$(document).ready(function() {   
$("ul.mainmenu li.menuhome").mouseover(function(){
    $(".arrow-spacer").show(); //When mouse over ...
    //Following event is applied to the subnav itself (making height of subnav 150px)
    $(this).find('.submenu').show().animate({height: '150px', opacity:'1'},{queue:false, duration:300})     
});

$("ul.mainmenu li.menuhome").mouseout(function(){ //When mouse out ...
    //Following event is applied to the subnav itself (making height of subnav 0px)
    $(this).find('.submenu').hide().animate({height:'0px', opacity:'0'},{queue:false, duration:200})
});

//menu itembackground color animation           
$("li").hover(function() {
    $(this).animate();},
    function() {
        $(".arrow-spacer").hide();
    }); 
});
</script>

That's it, I guess it may be simple, but it's been weeks and I still can't get it to work.

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

世俗缘 2024-10-28 07:31:41

I noticed that the anchor <a> tags have a margin on them. My first thing would be to try using padding instead. IE doesn't treat a hover in the margin the same way as other browsers.

东京女 2024-10-28 07:31:41

在某些情况下,在应放置在其他元素之上的元素上设置 z-index 会有所帮助。

在您的情况下,我会尝试在

in some cases it helps to set a z-index on elements that should placed in top of other elements.

In your case I would try to set the z-index on <ul class="submenu">

吃→可爱长大的 2024-10-28 07:31:41

不再眨眼了!我把一个单词hide()改成了stop(),现在iE上就没有闪烁了。但是...

显示菜单1次后,每次将鼠标移到链接下方或关闭链接时,菜单都会再次显示。

检查这个

www.universidadedoingles.com.br/dev

你将能够看到它的行为

No blinks anymore! I changed one word hide() to stop (), now there is no blinking on iE. but...

After you show the menu 1 time, everytime you get your mouse below the link or close the link, the menu shows up again.

check this

www.universidadedoingles.com.br/dev

you'll be able to see its behavior

混吃等死 2024-10-28 07:31:41

问题是,当您将鼠标悬停在 元素上时,

  • 的焦点就会丢失。
    您可以使用以下方法来克服这个问题。我避免使用
    标签,而是使用 JavaScript 函数将用户发送到首选位置。我使用 JavaScript 而不是 jQuery,希望使其更加不言自明。
  •         <script type="text/javascript" src="jquery.js" ></script>
            <script type='text/javascript'>
            $(document).ready(function() {
            $('#n li').hover(function() {
                    $('ul', this).slideDown(200);
            $(this).children('a:first').addClass('h');
              }, function() {
            $('ul', this).slideUp(200);
            $(this).children('a:first').removeClass('h');   
          });
            });
            function gotoPage(pnumber){
                var goto;
                if(pnumber==1){
                    goto="home.html";
                }else if(pnumber==2){
                goto="watsnew.html";
                }else if(pnumber==3){
                    goto="aboutus.html";
                }else if(pnumber==4){
                    goto="contactus.html";
                }
                window.location.href=goto;  
            }
    </script>
    
    <style type="text/css">
    #n {
        padding: 0;
        list-style: none;
        padding-left: 15px;
        padding-right: 15px;
        width:5em;
    }
    #n li { 
        /*display:inline;*/
        background: none;
        position: relative;
        z-index: 1;
        font-weight:bold;
        margin: 0 auto; 
    }
    #n li .h { 
        background-color: #fff;
        border-left: 1px solid #CF3;
        border-right: 1px solid #CF3;
        color: #576482;
        height:20px; }
    #n ul {
        position: absolute;
        display: none;
        margin: 0; padding: 0;
        list-style: none
        padding-bottom: 3px;
        width:200px;
    }   
    #n ul li {
        list-style-type:none;
        padding:10px;}
    #n ul li:hover {
        background:#960;}
    
    </style>
    
    
    <div>
    <ul id="n">
       <li>MENU
          <ul >
            <li value="1" onclick="gotoPage(this.value)">HOME</li>
            <li value="2" onclick="gotoPage(this.value)">WATS NEW</li>
            <li value="3" onclick="gotoPage(this.value)">ABOUT US</li>
            <li value="4" onclick="gotoPage(this.value)">CONTACT US</li>
          </ul>
       </li>
    <ul>
    </div>
    

    The thing is that the focus to <li> is lost when you mouse over an <a> element.
    Here is something you could use to overcome this. I avoided using the <a> tag, instead I used a JavaScript function to send the user to the preferred location. I used JavaScript rather than jQuery hoping to make it more self-explanatory.

            <script type="text/javascript" src="jquery.js" ></script>
            <script type='text/javascript'>
            $(document).ready(function() {
            $('#n li').hover(function() {
                    $('ul', this).slideDown(200);
            $(this).children('a:first').addClass('h');
              }, function() {
            $('ul', this).slideUp(200);
            $(this).children('a:first').removeClass('h');   
          });
            });
            function gotoPage(pnumber){
                var goto;
                if(pnumber==1){
                    goto="home.html";
                }else if(pnumber==2){
                goto="watsnew.html";
                }else if(pnumber==3){
                    goto="aboutus.html";
                }else if(pnumber==4){
                    goto="contactus.html";
                }
                window.location.href=goto;  
            }
    </script>
    
    <style type="text/css">
    #n {
        padding: 0;
        list-style: none;
        padding-left: 15px;
        padding-right: 15px;
        width:5em;
    }
    #n li { 
        /*display:inline;*/
        background: none;
        position: relative;
        z-index: 1;
        font-weight:bold;
        margin: 0 auto; 
    }
    #n li .h { 
        background-color: #fff;
        border-left: 1px solid #CF3;
        border-right: 1px solid #CF3;
        color: #576482;
        height:20px; }
    #n ul {
        position: absolute;
        display: none;
        margin: 0; padding: 0;
        list-style: none
        padding-bottom: 3px;
        width:200px;
    }   
    #n ul li {
        list-style-type:none;
        padding:10px;}
    #n ul li:hover {
        background:#960;}
    
    </style>
    
    
    <div>
    <ul id="n">
       <li>MENU
          <ul >
            <li value="1" onclick="gotoPage(this.value)">HOME</li>
            <li value="2" onclick="gotoPage(this.value)">WATS NEW</li>
            <li value="3" onclick="gotoPage(this.value)">ABOUT US</li>
            <li value="4" onclick="gotoPage(this.value)">CONTACT US</li>
          </ul>
       </li>
    <ul>
    </div>
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文