使用Jquery悬停时的菜单颜色渐变

使用Jquery悬停时的菜单颜色渐变,jquery,wordpress,menu,fade,Jquery,Wordpress,Menu,Fade,这个社区的一个成员足以产生一些Jquery代码,实际上,这些代码在滚动时淡出一种颜色,在滚动时淡出。为了方便起见,我在这里包含了JSFiddle链接。主要功能运行良好。但是,当我快速地将鼠标悬停在按钮上和按钮上时,似乎会出现延迟响应,最终导致悬停状态处于休眠状态,即使鼠标位于按钮上方。我非常接近我所寻找的,我非常感谢这个社区的支持 JSFiddle: Jquery $(document).ready(function () { //Set the anchor link opacity

这个社区的一个成员足以产生一些Jquery代码,实际上,这些代码在滚动时淡出一种颜色,在滚动时淡出。为了方便起见,我在这里包含了JSFiddle链接。主要功能运行良好。但是,当我快速地将鼠标悬停在按钮上和按钮上时,似乎会出现延迟响应,最终导致悬停状态处于休眠状态,即使鼠标位于按钮上方。我非常接近我所寻找的,我非常感谢这个社区的支持

JSFiddle:

Jquery

$(document).ready(function () {

    //Set the anchor link opacity to 0 and begin hover function
    $("#menu-sample-menu li a").hover(function () {

        //Fade to an opacity of 1 at a speed of 200ms
        $(this).fadeOut(0).addClass('hover').fadeIn(300);

        //On mouse-off
    }, function () {

        //Fade to an opacity of 0 at a speed of 100ms
        $(this).fadeOut(300)
            .queue(function () {
            $(this).removeClass('hover').fadeIn(0).dequeue()
        });

    });
});
HTML

提前感谢您的帮助


T

在开始设置任何动画之前,您可以告诉元素立即停止正在执行的操作

$("#menu-sample-menu li a").hover(function () { //Fade to an opacity of 1 at a speed of 200ms $(this).stop().fadeOut(0).addClass('hover').fadeIn(300); //On mouse-off }, function () { //Fade to an opacity of 0 at a speed of 100ms $(this).stop().fadeOut(300) .queue(function () { $(this).removeClass('hover').fadeIn(0).dequeue() }); }); $(“#菜单示例菜单li a”)。悬停(函数(){ //以200ms的速度衰减为1的不透明度 $(this.stop().fadeOut(0.addClass('hover').fadeIn(300); //关上鼠标 },函数(){ //以100ms的速度衰减为不透明度0 $(this).stop().fadeOut(300) .queue(函数(){ $(this.removeClass('hover').fadeIn(0.dequeue()) }); }); 尝试添加以停止当前正在运行的动画,如

...
$(this).stop().fadeOut(0).addClass('hover').fadeIn(300);
...


演示::

您可以使用此CSS3功能:

#access {
padding:0 20px;
background:#111;
box-shadow:0 0 7px rgba(0, 0, 0, .1);
}

#access ul {
float:left;
padding:0;
margin:0;
list-style:none;
font-weight:600;
text-transform:uppercase;
}

#access li {
position:relative;
float:left;
padding:0;
margin:0;
}

#access ul li:first-child {
padding-left:0;
}

#access a {
display:block;
padding:15px 24px;
color:#f0f0f0;
text-decoration:none;

}

#menu-sample-menu li {
color: black;
text-shadow: 0px 1px 4px #777;
background-color: green;
-webkit-transition: background-color 0.4s ease; /* CSS3 feature for your background-color transition */
-moz-transition: background-color 0.4s ease;
-o-transition: background-color 0.4s ease;
transition: background-color 0.4s ease;
padding: 0 12px 0 12px;
}

#menu-sample-menu li:hover {
background: orange;
}


#access li.current_page_item > a,
#access li.current-menu-item > a {
background: orange;
color: white;
text-decoration:none;
}

#access a span {
color:#999;
font-size:11px;
font-style:italic;
font-weight:normal;
line-height:1.62em;
text-transform:none;
}

而不是JQuery。下面是您可能想要的结果:

为什么不使用jQuery UI使用CSS转换或颜色转换?实际上我不想使用CSS3,因为缺少IE9支持。关于颜色转换,我很想看看它是如何工作的,以及与上面代码的区别。我真的不在乎IE,因为我是Linux迷…:-)如果有一个完美的通用浏览器,生活会变得更加轻松:)请检查小提琴链接好,+1:-)我一直很喜欢jsfiddles.Hi Sudhir,你能建议一种方法来实现这段代码,而不让链接文本随着背景消失吗。换句话说,我希望文本在背景淡入时保持不变。谢谢你提供的任何建议。大家好……我能为大家推荐一下如何实现上述代码而不使文本褪色吗。我不希望使用background-color属性,因为我可能希望在某个时候在hover类中包含背景图像。提前感谢您提供的任何帮助谢谢您提供css3替代品。我想使用Jquery,这样它就可以在Ie9中得到支持。这正是我需要的。谢谢你嗨,Caleb,你能给我一些指导,告诉我如何淡出背景,而不让文本链接淡出背景吗?谢谢!也许这会对你有所帮助:
...
$(this).stop().fadeOut(0).addClass('hover').fadeIn(300);
...
...
$(this).stop().fadeOut(300)
    .queue(function () {
         $(this).removeClass('hover').fadeIn(0).dequeue()
});
....
#access {
padding:0 20px;
background:#111;
box-shadow:0 0 7px rgba(0, 0, 0, .1);
}

#access ul {
float:left;
padding:0;
margin:0;
list-style:none;
font-weight:600;
text-transform:uppercase;
}

#access li {
position:relative;
float:left;
padding:0;
margin:0;
}

#access ul li:first-child {
padding-left:0;
}

#access a {
display:block;
padding:15px 24px;
color:#f0f0f0;
text-decoration:none;

}

#menu-sample-menu li {
color: black;
text-shadow: 0px 1px 4px #777;
background-color: green;
-webkit-transition: background-color 0.4s ease; /* CSS3 feature for your background-color transition */
-moz-transition: background-color 0.4s ease;
-o-transition: background-color 0.4s ease;
transition: background-color 0.4s ease;
padding: 0 12px 0 12px;
}

#menu-sample-menu li:hover {
background: orange;
}


#access li.current_page_item > a,
#access li.current-menu-item > a {
background: orange;
color: white;
text-decoration:none;
}

#access a span {
color:#999;
font-size:11px;
font-style:italic;
font-weight:normal;
line-height:1.62em;
text-transform:none;
}