如何在悬停或单击 lavalamp jquery 菜单时更改链接颜色?
我在水平菜单中使用 LavaLamp 脚本
http:// /www.gmarwaha.com/blog/2007/08/23/lavalamp-for-jquery-lovers/
活动或悬停的链接现在为灰色。 我想更改悬停(或单击)菜单项的颜色,如下所示:
http://screencast.com/ t/WU02S3jF
HTML:
`<ul class="lavaLamp">
<li><a href="#">Home</a></li>
<li><a href="#">Plant a tree</a></li>
<li><a href="#">Travel</a></li>
<li><a href="#">Ride an elephant</a></li>
</ul>`
Javascript:
(function ($) { $.fn.lavaLamp = function (o) {
o = $.extend({ fx: "linear", speed: 500, click: function () { } }, o || {});
return this.each(function () {
var me = $(this), noop = function () { },
$back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
$li = $("li", this),
curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
$li.not(".back").hover(function () {
move(this);
}, noop);
$(this).hover(noop, function () {
move(curr);
});
$li.click(function (e) {
setCurr(this);
return o.click.apply(this, [e, this]);
});
setCurr(curr);
function setCurr(el) {
$back.css({"left":el.offsetLeft+"px","width":el.offsetWidth+"px"});
curr = el;
};
function move(el) {
$back.each(function () {
$(this).dequeue();
}
).animate({
width: el.offsetWidth,
left: el.offsetLeft
}, o.speed, o.fx);
};
});
};})(jQuery);
I am using LavaLamp script for my horizontal menu
http://www.gmarwaha.com/blog/2007/08/23/lavalamp-for-jquery-lovers/
Active or hovered link is now grey.
I want to change color on hover (or clicked) menu item, to look like this:
http://screencast.com/t/WU02S3jF
HTML:
`<ul class="lavaLamp">
<li><a href="#">Home</a></li>
<li><a href="#">Plant a tree</a></li>
<li><a href="#">Travel</a></li>
<li><a href="#">Ride an elephant</a></li>
</ul>`
Javascript:
(function ($) { $.fn.lavaLamp = function (o) {
o = $.extend({ fx: "linear", speed: 500, click: function () { } }, o || {});
return this.each(function () {
var me = $(this), noop = function () { },
$back = $('<li class="back"><div class="left"></div></li>').appendTo(me),
$li = $("li", this),
curr = $("li.current", this)[0] || $($li[0]).addClass("current")[0];
$li.not(".back").hover(function () {
move(this);
}, noop);
$(this).hover(noop, function () {
move(curr);
});
$li.click(function (e) {
setCurr(this);
return o.click.apply(this, [e, this]);
});
setCurr(curr);
function setCurr(el) {
$back.css({"left":el.offsetLeft+"px","width":el.offsetWidth+"px"});
curr = el;
};
function move(el) {
$back.each(function () {
$(this).dequeue();
}
).animate({
width: el.offsetWidth,
left: el.offsetLeft
}, o.speed, o.fx);
};
});
};})(jQuery);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将以下内容添加到您的 css CSS:
此外,如果您希望它在选择时也发生变化,您应该创建一个类,该类在选择时添加到链接的
li
元素中,并在选择另一个元素时删除。例如,abc
类将添加到选定的链接li
元素中:Add the following to your css CSS:
in addition if you want it also to change upon select you should create a class that is added to the link's
li
element when it is selected and removed when another is selected. for example theabc
class would be added to the selected linkli
element:我认为你唯一需要做的就是改变 css 背景颜色:
I think the only thing you need to do is change the css background-color: