带有 sIFR 的 Javascript 选项卡菜单

发布于 2024-08-06 22:37:04 字数 3594 浏览 2 评论 0原文

我正在开发一个两级菜单,例如此页面上的动态驱动器示例。目标是在主导航onmouseover下方显示子导航层,并在一定时间间隔后恢复到每个页面的默认子导航层。它可以工作,但有一个大问题:我在主要导航项上使用 sIFR(s 位于

  • s 内部)。脚本逻辑不适用于 sIFR 化的项目,因为它的目标是已被替换的 标记。
  • 我尝试更改脚本以定位父

  • ,但它只是搞砸了主导航。我对 Javascript 不是很了解,所以任何建议都会受到赞赏!
  • 一个想法:sIFR 是否可以替换每个导航,而不是替换每个

  • ?或者 仍然对菜单脚本不可用?
  • 我并没有接受这个 javascript 解决方案,事实上,我使用简单的 Javascript 显示/隐藏方法尝试了自己的一些其他方法。但是,该脚本具有我正在寻找的“恢复默认”行为。

    --> 来自 Dynamic Drive 的 Javascript 菜单源

    • 主导航源:

    <div id="mainNav">
    <ul>
        // rel="subnav1" shows the "subnav1" layer in the snippet below
        <li class="navLi"><a href="around-othello.php" rel="subnav1">Around Othello</a></li>
    
        // rel="subnav2" shows the "subnav2" layer in the snippet below
        <li class="navLi"><a href="living-here.php" rel="subnav2">Living Here</a></li>
    
        // rel="subnav3" shows the "subnav3" layer in the snippet below
        <li class="navLi"><a href="link-to-it.php">Link to it</a></li>
    
        <li class="navLi"><a href="whats-new.php">What's New</a></li>
    
        <li class="navLi"><a href="contact.php">Contact</a></li>
    
        <li class="navLi"><a href="retail.php">Retail Hub</a></li>
    </ul>
    </div>
    

    • sIFR 替换主要导航项目

    sIFR.replace(grotesqueMT, {
    selector: 'li.navLi',
    tuneWidth:4,
    forceSingleLine:true,
    ratios:[8, 1.3, 11, 1.21, 12, 1.2, 14, 1.19, 21, 1.16, 28, 1.13, 38, 1.12, 61, 1.11, 94, 1.1, 95, 1.09, 103, 1.1, 107, 1.09, 110, 1.1, 119, 1.09, 120, 1.1, 1.09],
    css: ['.sIFR-root { background-color:#5a7e92; color:#ffffff; font-size:18; }'
          ,'a { color:#ffffff; text-decoration:none; }'
          ,'a:link { color:#ffffff; text-decoration:none; }'
          ,'a:hover { color:#f0eed6; text-decoration:underline; }'
          ]
    });
    

    • Subnav 源(单独的代码片段)

    <div id="subnav1" class="subnav">
    <ul>
        <li><a href="around-othello.php">Around Othello</a></li>
        <li class="pipe"> | </li>
        <li><a href="around-othello.php?p=your-big-backyard">Your Big Backyard</a></li>
        <li class="pipe"> | </li>
        <li><a href="around-othello.php?p=explore-the-area">Explore the Area</a></li>
        <li class="pipe"> | </li>
        <li><a href="communityBuzz">Community Buzz</a></li>
    </ul>
    </div>
    
    <div id="subnav2" class="subnav">
    <ul>
        <li><a href="around-othello.php">Around Othello</a></li>
        <li class="pipe"> | </li>
        <li><a href="communityBuzz">Community Buzz</a></li>
    </ul>
    </div>
    
    <div id="subnav3" class="subnav">
    <ul>
        <li><a href="living-here.php">Living Here</a></li>
        <li class="pipe"> | </li>
        <li><a href="living-here.php?p=living-green">Living Green</a></li>
    </ul>
    </div>
    

    I am working on a two-level menu like the Dynamic Drive examples on this page. The goal is to show a subnav layer below the main nav onmouseover, reverting to each page's default subnav layer after a timed interval. It works, except for a big problem: I am using sIFR on the main navigation items (<a>s inside of <li>s). The script logic doesn't work on the sIFRized items, because it targets <a rel=""> tags, which have been replaced.

    I tried changing the script to target the parent <li>s, but it just screwed up the main nav. I am not very advanced with Javascript so any advice is appreciated!

    One idea: is it possible to sIFR replace each navigation <a> instead of replacing each <li>? Or would the <a rel=""> still be unavailable to the menu script?

    I'm not married to this javascript solution, in fact I tried a few other methods of my own using simple Javascript show/hide methods. However, this script has the "reverting to default" behavior I am looking for.

    --> Javascript menu source from Dynamic Drive

    • Main navigation source:

    <div id="mainNav">
    <ul>
        // rel="subnav1" shows the "subnav1" layer in the snippet below
        <li class="navLi"><a href="around-othello.php" rel="subnav1">Around Othello</a></li>
    
        // rel="subnav2" shows the "subnav2" layer in the snippet below
        <li class="navLi"><a href="living-here.php" rel="subnav2">Living Here</a></li>
    
        // rel="subnav3" shows the "subnav3" layer in the snippet below
        <li class="navLi"><a href="link-to-it.php">Link to it</a></li>
    
        <li class="navLi"><a href="whats-new.php">What's New</a></li>
    
        <li class="navLi"><a href="contact.php">Contact</a></li>
    
        <li class="navLi"><a href="retail.php">Retail Hub</a></li>
    </ul>
    </div>
    

    • sIFR replacement for main nav items

    sIFR.replace(grotesqueMT, {
    selector: 'li.navLi',
    tuneWidth:4,
    forceSingleLine:true,
    ratios:[8, 1.3, 11, 1.21, 12, 1.2, 14, 1.19, 21, 1.16, 28, 1.13, 38, 1.12, 61, 1.11, 94, 1.1, 95, 1.09, 103, 1.1, 107, 1.09, 110, 1.1, 119, 1.09, 120, 1.1, 1.09],
    css: ['.sIFR-root { background-color:#5a7e92; color:#ffffff; font-size:18; }'
          ,'a { color:#ffffff; text-decoration:none; }'
          ,'a:link { color:#ffffff; text-decoration:none; }'
          ,'a:hover { color:#f0eed6; text-decoration:underline; }'
          ]
    });
    

    • Subnav source (a separate code snippet)

    <div id="subnav1" class="subnav">
    <ul>
        <li><a href="around-othello.php">Around Othello</a></li>
        <li class="pipe"> | </li>
        <li><a href="around-othello.php?p=your-big-backyard">Your Big Backyard</a></li>
        <li class="pipe"> | </li>
        <li><a href="around-othello.php?p=explore-the-area">Explore the Area</a></li>
        <li class="pipe"> | </li>
        <li><a href="communityBuzz">Community Buzz</a></li>
    </ul>
    </div>
    
    <div id="subnav2" class="subnav">
    <ul>
        <li><a href="around-othello.php">Around Othello</a></li>
        <li class="pipe"> | </li>
        <li><a href="communityBuzz">Community Buzz</a></li>
    </ul>
    </div>
    
    <div id="subnav3" class="subnav">
    <ul>
        <li><a href="living-here.php">Living Here</a></li>
        <li class="pipe"> | </li>
        <li><a href="living-here.php?p=living-green">Living Green</a></li>
    </ul>
    </div>
    

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

    发布评论

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

    评论(1

    傲影 2024-08-13 22:37:04

    说真的,省得麻烦,不要在这里使用 sIFR。

    Seriously, save yourself the trouble and don't use sIFR here.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文