如何在悬停或单击 lavalamp jquery 菜单时更改链接颜色?

发布于 2024-11-30 02:56:05 字数 1905 浏览 2 评论 0原文

我在水平菜单中使用 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 技术交流群。

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

发布评论

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

评论(2

指尖上得阳光 2024-12-07 02:56:05

将以下内容添加到您的 css CSS:

.lavaLamp li a:hover {
    color: white;
    background: lightblue;
    //anything else you want to add here
}

此外,如果您希望它在选择时也发生变化,您应该创建一个类,该类在选择时添加到链接的 li 元素中,并在选择另一个元素时删除。例如,abc 类将添加到选定的链接 li 元素中:

.abc a {
    color: white;
    background: lightblue;
    //anything else you want to add here
}

Add the following to your css CSS:

.lavaLamp li a:hover {
    color: white;
    background: lightblue;
    //anything else you want to add here
}

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 the abc class would be added to the selected link li element:

.abc a {
    color: white;
    background: lightblue;
    //anything else you want to add here
}
孤城病女 2024-12-07 02:56:05

我认为你唯一需要做的就是改变 css 背景颜色:

.lavaLampNoImage li.back {
    border: 1px solid #000;
    background-color: blue; // change this line to the correct color
    width: 9px;
    height: 30px;
    z-index: 8;
    position: absolute;
}

I think the only thing you need to do is change the css background-color:

.lavaLampNoImage li.back {
    border: 1px solid #000;
    background-color: blue; // change this line to the correct color
    width: 9px;
    height: 30px;
    z-index: 8;
    position: absolute;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文