jQuery下拉菜单ie9兼容模式

时间:2012-08-29 15:05:42

标签: jquery internet-explorer drop-down-menu ie-compatibility-mode

我创建了一个简单的jQuery下拉菜单。在FF,Chrome,ie9工作。但是,它在兼容模式下不起作用。

HTML:

<div class="navBarCont">
<ul class="navBar gradient shadow" id="navBar">
    <li><a href="index.html">Home</a></li>
    <li class="selected"><a href="about_us.html">About Us</a></li>
    <li><a href="faq.html">FAQs</a></li>
    <li>Upcoming Events / News</li>                    
    <li>Educational
        <ul class="subnav">
            <li><a href="osteooftheknee.html">Osteoarthritis of the Knee</a></li>
            <li><a href="benefitsofexercise.html">Benefits of Exercise</a></li>
            <li><a href="didyouknow.html">Did You Know?</a></li>
        </ul>
    </li>
    <li><a href="contact.html">Contact Us</a></li>
</ul>
</div>

JS:

$(document).ready(function(){
    $('.navBar li').hover(function () {
        $('ul', this).stop().slideDown(100);
    }, function () {
        $('ul', this).stop().slideUp(100);
    }); 
});

CSS:


    .navBarCont {
        position: relative;
        top: -15px;
        z-index: auto;
        width: 714px;
        margin: 0 auto;
        background:#fff;
    }
    .navBar {
        cursor: pointer;
        z-index: 95;
        position:relative;
        height: 28px;
        float: left;
        color: #ffffff;
        font-family: arial;
        font-size: .97em;
        -webkit-border-radius: 5px;
        -moz-border-radius: 5px;
        border-radius: 5px;
        background: #fff;
    }
    .navBar>li {
        float: left;
        display: block;
        height:23px;
        border-right: thin solid #ffffff;
        padding: 5px 18px 0;
        position: relative;
        background: rgb(109,179,242); /* Old browsers */
        /* IE9 SVG, needs conditional override of 'filter' to 'none' */
        background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzZkYjNmMiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUwJSIgc3RvcC1jb2xvcj0iIzU0YTNlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjUxJSIgc3RvcC1jb2xvcj0iIzM2OTBmMCIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiMxZTY5ZGUiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+);
        background: -moz-linear-gradient(top, rgba(109,179,242,1) 0%, rgba(84,163,238,1) 50%, rgba(54,144,240,1) 51%, rgba(30,105,222,1) 100%); /* FF3.6+ */
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, rgba(109,179,242,1)), color-stop(50%, rgba(84,163,238,1)), color-stop(51%, rgba(54,144,240,1)), color-stop(100%, rgba(30,105,222,1))); /* Chrome,Safari4+ */
        background: -webkit-linear-gradient(top, rgba(109,179,242,1) 0%, rgba(84,163,238,1) 50%, rgba(54,144,240,1) 51%, rgba(30,105,222,1) 100%); /* Chrome10+,Safari5.1+ */
        background: -o-linear-gradient(top, rgba(109,179,242,1) 0%, rgba(84,163,238,1) 50%, rgba(54,144,240,1) 51%, rgba(30,105,222,1) 100%); /* Opera 11.10+ */
        background: -ms-linear-gradient(top, rgba(109,179,242,1) 0%, rgba(84,163,238,1) 50%, rgba(54,144,240,1) 51%, rgba(30,105,222,1) 100%); /* IE10+ */
        background: linear-gradient(top, rgba(109,179,242,1) 0%, rgba(84,163,238,1) 50%, rgba(54,144,240,1) 51%, rgba(30,105,222,1) 100%); /* W3C */
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6db3f2', endColorstr='#1e69de', GradientType=0 ); /* IE6-8 */
        text-align: center;
    }
    .navBar li:hover, .arthritis .title a:hover {
        background: #a5cdef; /* Old browsers */
        background: -moz-linear-gradient(top,  #a5cdef 0%, #4e8edb 50%, #337add 51%, #163a9e 100%); /* FF3.6+ */
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cdef), color-stop(50%,#4e8edb), color-stop(51%,#337add), color-stop(100%,#163a9e)); /* Chrome,Safari4+ */
        background: -webkit-linear-gradient(top,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* Chrome10+,Safari5.1+ */
        background: -o-linear-gradient(top,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* Opera 11.10+ */
        background: -ms-linear-gradient(top,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* IE10+ */
        background: linear-gradient(to bottom,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* W3C */
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a5cdef', endColorstr='#163a9e',GradientType=0 ); /* IE6-9 */
    }
    .navBar li.selected>a,
    .navBar li.selected{
        color: #ffffb9;
    }
    .navBar li.selected {
        background: #a5cdef; /* Old browsers */
        background: -moz-linear-gradient(top,  #a5cdef 0%, #4e8edb 50%, #337add 51%, #163a9e 100%); /* FF3.6+ */
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#a5cdef), color-stop(50%,#4e8edb), color-stop(51%,#337add), color-stop(100%,#163a9e)); /* Chrome,Safari4+ */
        background: -webkit-linear-gradient(top,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* Chrome10+,Safari5.1+ */
        background: -o-linear-gradient(top,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* Opera 11.10+ */
        background: -ms-linear-gradient(top,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* IE10+ */
        background: linear-gradient(to bottom,  #a5cdef 0%,#4e8edb 50%,#337add 51%,#163a9e 100%); /* W3C */
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a5cdef', endColorstr='#163a9e',GradientType=0 ); /* IE6-9 */
    }
    .navBar>li:last-child {
        border-right: none;
        -webkit-border-radius: 0 5px 5px 0;
        -moz-border-radius: 0 5px 5px 0;
        border-radius: 0 5px 5px 0;
    }
    .navBar>li:first-child {
        -webkit-border-radius: 5px 0 0 5px;
        -moz-border-radius: 5px 0 0 5px;
        border-radius: 5px 0 0 5px;
    }
    .navBar ul {
        position: absolute;
        left: 0;
        text-decoration: none;
        list-style: none;
        display: none;
        padding: 10px;
        text-align: left;
        border-top: none;
        z-index: 90;
        top: 28px;
        color: #fff;
        -moz-border-radius-topleft: 0px;
        -moz-border-radius-topright: 0px;
        -moz-border-radius-bottomright: 5px;
        -moz-border-radius-bottomleft: 5px;
        -webkit-border-radius: 0px 0px 5px 5px;
        border-radius: 0px 0px 5px 5px;
        background: #6db3f2; /* Old browsers */
        background: -moz-linear-gradient(top,  #6db3f2 0%, #1e69de 100%); /* FF3.6+ */
        background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6db3f2), color-stop(100%,#1e69de)); /* Chrome,Safari4+ */
        background: -webkit-linear-gradient(top,  #6db3f2 0%,#1e69de 100%); /* Chrome10+,Safari5.1+ */
        background: -o-linear-gradient(top,  #6db3f2 0%,#1e69de 100%); /* Opera 11.10+ */
        background: -ms-linear-gradient(top,  #6db3f2 0%,#1e69de 100%); /* IE10+ */
        background: linear-gradient(to bottom,  #6db3f2 0%,#1e69de 100%); /* W3C */
        filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6db3f2', endColorstr='#1e69de',GradientType=0 ); /* IE6-9 */
    }
    .navBar a {
        color: #fff;
        text-decoration: none;
    }
    .navBar ul li {
        clear: both;
        float: left;
        padding: 5px;
        border-right: none;
    }
    .navBar ul li a {
        color: #fff;
        text-decoration: none;
    }

1 个答案:

答案 0 :(得分:1)

试试这个

$(document).ready(function(){
    $('.navBar li').hover(function () {
           $('ul', this).stop(true,true).slideDown(100);
}, function () {
    $('ul', this).stop(true,true).slideUp(100);
});​
   });