1

I was wondering if anyone could assist me on solving this problem with jQuery MagicLine Navigation (http://css-tricks.com/jquery-magicline-navigation/)

Seems to be that when the page loads the li id="magic-line" always seem to extend 10 px larger than it should on the "Home" link. When you have hover over the home link the line reduces size to what it should be.

The navigation is on http://www.jonasbabrauskas.com/jncustoms

in the html it seems to move from width of 77px to with of 58px when mouse is hovered over top. Does anyone have a solution on how I can get it to be its correct size when the mouse is not hovered over it? All other links seem to work perfectly fine. I've also tried using LavaLamp plugin and had the same issue. I don't know if it is because of an @font-face I used for the navigation.

here is my code. Thank you.

jQuery

$(function() {

var $el, leftPos, newWidth;
    $mainNav2 = $("#example-two");

/*
    EXAMPLE ONE
*/

/* Add Magic Line markup via JavaScript, because it ain't gonna work without */
$("#example-one").append("<li id='magic-line'></li>");

/* Cache it */
var $magicLine = $("#magic-line");

$magicLine
    .width($(".current_page_item").width())
    .css("left", $(".current_page_item a").position().left)
    .data("origLeft", $magicLine.position().left)
    .data("origWidth", $magicLine.width());

$("#example-one li").find("a").hover(function() {
    $el = $(this);
    leftPos = $el.position().left;
    newWidth = $el.parent().width();

    $magicLine.stop().animate({
        left: leftPos,
        width: newWidth
    });
}, function() {
    $magicLine.stop().animate({
        left: $magicLine.data("origLeft"),
        width: $magicLine.data("origWidth")
    });    
});
 });

HTML

    <ul class="group" id="example-one">
        <li class="current_page_item">
            <a href="#">Home</a>
        </li>
        <li><a href="#">Buy Tickets</a></li>

        <li><a href="#">Group Sales</a></li>
        <li><a href="#">Reviews</a></li>
        <li><a href="#">The Show</a></li>

    </ul>

CSS

#example-one { 
    margin: 0 auto; 
    list-style: none; 
    position: relative; 
    width: 500px; 
}
#example-one li { 
    display: inline-block;  
}
#example-one a { 
    float: left;
    padding: 6px 10px 4px 10px;
}
#example-one a:hover { 
    color: #000; 
}
#magic-line { 
    position: absolute;
    bottom: -2px; 
    left: 0; 
    width: 100px; 
    height: 2px; 
    background: #000;
}
.current_page_item a { 
    color: #000 !important; 
}
.ie6 #example-one li, .ie7 #example-one li { 
    display: inline; 
}
.ie6 #magic-line {
    bottom: -3px;
}     
EpzOne
  • 11
  • 2

1 Answers1

1

I am having the same issue using a font from Google Web Fonts (specifically, I'm using 'Abel' found here: http://www.google.com/webfonts/specimen/Abel). When I remove the font styling, the magic line aligns correctly. Seems to be a bummer, since I really wanted to use both the font and the cool magic line! I don't know if there's a way to combine the two, but I can confirm that the problem seems to come from the simultaneous use of font-face and magic line.

Edit: I found a solution! MagicLine Navigation: Problem with @font-face embedded fonts! The answer seems to be to make sure the jQuery script is loaded after font is fully loaded to make sure the script is working with all the correct widths. From their site:

Instead of:

jQuery(document).ready(function($) {

my script now starts with:

$(window).bind("load", function() {
j0k
  • 22,600
  • 28
  • 79
  • 90