如何改变链接的颜色时,悬停或点击lavalamp jquery菜单

How to change link color when hovering or clicking lavalamp jquery menu?

本文关键字:悬停 菜单 jquery lavalamp 颜色 何改变 改变 链接      更新时间:2023-09-26

我正在使用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);

添加以下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
}

我认为你唯一需要做的就是改变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;
}