jquery - 动画菜单使用 jQuery 需要帮助

标签 jquery html css navigation

我正在设计一个用于学习目的的网站,出于某种原因,我的导航栏在所有选项卡上都停留在“悬停”状态。我正在学习的教程非常深入,但我已经研究代码几个小时了,我想我只是没有足够的知识来找出问题所在。在排除故障时,我查看了源代码并复制了它(从他们的示例中),但仍然有同样的问题。按钮都“始终”处于悬停状态,因此 Java Script 似乎没有执行任何操作。

教程:http://www.shopdev.co.uk/blog/animated-menus-using-jquery/

我为此创建了 3 张图像(与教程略有不同)

bkrd.png= 400 像素高的窄图像,重复背景工具栏(无菜单选项卡) spritedown.png= 显示正常按钮状态(主页和投资组合)的 sprite 81 像素高
spriteover.png= 显示按钮悬停状态的 Sprite 。 81 像素高

我的代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Animated Menu Demo</title>

<style>
body {
    background-color:#333333;
    margin:0;
}



/* Menu Body */
ul#menu {
    width:80%;
    height:400px;
    background:url(bkrd.png) repeat-x;
    list-style:none;
    margin:0;
    padding:0;
    padding-top:109px; /* distance from top where i need the sprite to start*/
    padding-left:20%;
}

/* Float LI Elements - horizontal display */
ul#menu li {
    float:left;
}

/* Link - common attributes */
ul#menu li a {
    background:url(spritedown.png) no-repeat scroll top left;
    display:block;
    height:81px;
    position:relative;
}

/* Specify width and background position attributes specifically for the class: "home" */
ul#menu li a.home {
    width:159px;
    background-position:0px 0px;
}

/* Specify width and background position attributes specifically for the class: "portfolio" */
ul#menu li a.portfolio {
    width:157px;
    background-position:-159px 0px;
}

/* Span (on hover) - common attributes */
ul#menu li a span {
    background:url(spriteover.png) no-repeat scroll bottom left;
    display:block;
    position:absolute;
    top:0;
    left:0;
    height:81px;
    width:100%;
    z-index:100;
}

/* Span (on hover) - display pointer */
ul#menu li a span:hover {
    cursor:pointer;
}

/* Shift background position on hover for the class: "home" */
ul#menu li a.home span {
width:159px;
    background-position:0px 0px;
}

/* Shift background position on hover for the class: "portfolio" */
ul#menu li a.portfolio span {
    background-position:-159px 0px;
}
</style>

脚本:

<!-- Include jQuery Library -->
<script src="jquery-1.2.2.pack.js" type="text/javascript"></script>

<!-- Let's do the animation -->
<script type="text/javascript">
$(function() {
    // set opacity to nill on page load
    $("ul#menu span").css("opacity","0");
    // on mouse over
    $("ul#menu span").hover(function () {
        // animate opacity to full
        $(this).stop().animate({
            opacity: 1
        }, 'slow');
    },
    // on mouse out
    function () {
        // animate opacity to nill
        $(this).stop().animate({
            opacity: 0
        }, 'slow');
    });
});
</script>
</head>

正文:

<body>
<ul id="menu">
    <li><a href="#" class="home"><span></span></a></li>
    <li><a href="#" class="portfolio"><span></span></a></li>
</ul>
</body>

</html>

最佳答案

你还没有打开你的 jquery 脚本 jsfiddle...你有没有在你的 head 中包含你的 jquery.js?你在 http://jsfiddle.net/7JxMF/1/ 上使用 jquery 的 jsfiddle

关于jquery - 动画菜单使用 jQuery 需要帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14407257/

相关文章:

javascript - 单击两个输入的相同标签名称的关闭图标时取消选中选中的输入

fiddle 更新后 JavaScript 和 jQuery 无法工作

javascript - 圆形按钮溢出的波纹效果

java - multipart/form-data 与字符一起使用以访问 jsp

javascript - 具有动态 div 的 CSS 垂直居中

css - Firefox:calc() 无效的属性值

javascript - GMAIL 如何有一个显示未读邮件数的图标?

javascript - 选择选项卡时将焦点设置在弹出窗口上

jquery - 在 jquery 中使用动态添加的元素

html - 没有 JS 或媒体查询的智能 1 列或 1 行元素?