Question

I have the lava-lamp navigation basically working, but I have a small issue.

I'm using this LavaLamp menu plugin and am trying to get my navigation to look like this:

enter image description here

So I have it working, except the issue I'm having is that I need the links to be one color (black) when the lava-lamp image isn't over them, and white when it is. Hover works fine for that, but the issue comes with class current (the lava-lamp hover effect is on class current by default).

If I set the link to white for class current, the link stays white even when you hover over a different navigation link.

I assume some simple JavaScript could fix this, but I'm not that knowledgeable in it and would appreciate if anyone could share the solution with me.

Était-ce utile?

La solution

Just rewrite the plugin to add colors ?

//lavalamp plugin
(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) {
                $(el).find('a')
                     .css('color', o.hover_color).end()
                     .siblings('li').find('a')
                     .css('color', o.color);
                $back.each(function() {
                    $(this).dequeue();
                }).animate({
                    width: el.offsetWidth,
                    left: el.offsetLeft
                }, o.speed, o.fx);
            };
        });
    };
})(jQuery);

call plugin with colors

$(document).ready(function() {

    $(".lavaLamp").lavaLamp({
        fx: "backout",
        speed: 700,
        color: "#fff",
        hover_color: "#000"
    });

});​

FIDDLE

Added color animation (requires the easing plugin / jQuery UI) - FIDDLE

Autres conseils

set your color with !important like this

color:black !important;    

may be this will help you out

See updated fiddle: http://jsfiddle.net/DRPsA/5/

Basically, you can just add this:

    $(".lavaLampWithImage .current").addClass("theCurrentLink");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

    $(".lavaLampWithImage").hover(function() {    
          $(this).find(".current").removeClass("current");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  } , 
        function() {    
          $(this).find(".theCurrentLink").addClass("current");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        } 
);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top