切换和动画锚链接不再导航

发布于 2024-12-04 02:51:19 字数 1894 浏览 3 评论 0原文

我使用 jQuery.toggle 和 .animate 作为位于页面底部的导航菜单。导航由两个 div 组成,一个作为外部容器,另一个作为包含导航按钮等的内部容器。

我想要实现的是;您单击导航,它的位置会向上移动,要关闭导航,您只需再次单击它,它就会以动画方式返回到页面底部的原始位置。

我遇到的问题是,当您单击导航按钮时,没有任何反应,即使浏览器状态栏显示目标 URL,它也不会像应有的那样将您带到链接。

这是链接

jQuery:

$('#navContainer').toggle(function() {
    $('#navInner').animate({
        bottom: '+=350'
    }, 400, 'swing', function() {
    });
}, function() {
    $('#navInner').animate({
        bottom: '-=350'
    }, 400, 'swing', function() {
    });
});

CSS:

#navContainer {
    background-color:#0FF;
    height:520px;
    margin:0px 0px 0px 60px;
    position:fixed;
    cursor:pointer;
    bottom: 0px;
}

#navInner {
    background:url(../images/appinstructions/nav2.png);
    background-repeat:no-repeat;
    width:638px;
    height:491px;
    position:absolute;
    bottom:-350px;
}

HTML:

<div id="navContainer">
    <div id="navInner">
        <a id="navhomeBtn" href="appInstuc.html"></a>  
        <a id="navhelpBtn" href="appInstuc.html"></a>
        <a id="geBtn" href="http://www.ge.com/" target="_blank"></a>
        <div id="pages">
            <a href="ipadApp1.html"><img src="images/appinstructions/page1.png" alt="page 1"   class="page"/></a>
            <a href="app1-1.html"><img src="images/appinstructions/page2.png" alt="page 2" class="page"/></a>
            <a href="appRoots.html"><img src="images/appinstructions/page3.png"  alt="page3"class="page"/></a>
        </div><!--close pages--> 
    </div><!--close navInner--> 
</div><!--close navContainer--> 

I am using jQuery.toggle and .animate for a navigation menu that sits at the bottom of the page. The nav consists of two divs, one as a outer container and the other as a inner container that holds the nav buttons etc.

What I am trying to achieve is; you click on the nav and it's position animates up and to close the nav you simply click on it again and it animates back down to it's original position at the bottom of the page.

The issue I am having is when you click on the nav buttons nothing happens, it doesn't take you to the link like it should even though the browser status bar shows the target URL.

Here's a link

jQuery:

$('#navContainer').toggle(function() {
    $('#navInner').animate({
        bottom: '+=350'
    }, 400, 'swing', function() {
    });
}, function() {
    $('#navInner').animate({
        bottom: '-=350'
    }, 400, 'swing', function() {
    });
});

CSS:

#navContainer {
    background-color:#0FF;
    height:520px;
    margin:0px 0px 0px 60px;
    position:fixed;
    cursor:pointer;
    bottom: 0px;
}

#navInner {
    background:url(../images/appinstructions/nav2.png);
    background-repeat:no-repeat;
    width:638px;
    height:491px;
    position:absolute;
    bottom:-350px;
}

HTML:

<div id="navContainer">
    <div id="navInner">
        <a id="navhomeBtn" href="appInstuc.html"></a>  
        <a id="navhelpBtn" href="appInstuc.html"></a>
        <a id="geBtn" href="http://www.ge.com/" target="_blank"></a>
        <div id="pages">
            <a href="ipadApp1.html"><img src="images/appinstructions/page1.png" alt="page 1"   class="page"/></a>
            <a href="app1-1.html"><img src="images/appinstructions/page2.png" alt="page 2" class="page"/></a>
            <a href="appRoots.html"><img src="images/appinstructions/page3.png"  alt="page3"class="page"/></a>
        </div><!--close pages--> 
    </div><!--close navInner--> 
</div><!--close navContainer--> 

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

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

发布评论

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

评论(1

み青杉依旧 2024-12-11 02:51:19

问题似乎出在 .toggle 函数上,如果您使用 .click 链接就可以工作。使用 .toggle 链接不起作用的原因是这些链接是 #navInner div 的子级,因此单击链接会触发 .toggle代码>事件。

我建议改为这样做:

var showing = false;
$('#navInner').click(function(e){

    if(e.target != this) return;

    // Work out which direction we're moving in
    var topValue = "";
    if(showing){
        topValue = "+=350";
    } else {
        topValue = "-=350";
    }   

    // Change the showing variable to opposite
    showing = !(showing);

    // Begin the animation
    $(this).animate({ 
        top: topValue
    }, 400, 'swing', function(){
        // Do nothing
    });

});

这将为您提供切换方法的效果,但如果您单击其中一个子元素,它不会为 #navInner div 设置动画。

如果您确实希望它仍然对 #navInner div 进行动画处理,只需删除以下行:(

if(e.target != this) return;

尽管因为它们是链接并将您带到不同的页面,所以我怀疑对 #navInner div 进行动画处理div 是需要的)

The problem seems to be with the .toggle function, if you use .click the links work. The reason the links don't work using .toggle is because the links are children of the #navInner div, so clicking the link fires the .toggle event.

I would suggest doing something like this instead:

var showing = false;
$('#navInner').click(function(e){

    if(e.target != this) return;

    // Work out which direction we're moving in
    var topValue = "";
    if(showing){
        topValue = "+=350";
    } else {
        topValue = "-=350";
    }   

    // Change the showing variable to opposite
    showing = !(showing);

    // Begin the animation
    $(this).animate({ 
        top: topValue
    }, 400, 'swing', function(){
        // Do nothing
    });

});

This will give you the effect of the toggle method, but if you click one of the child elements it will not animate the #navInner div.

If you do want it to still animate the #navInner div, just remove the following line:

if(e.target != this) return;

(although because they are links and taking you off to a different page, I doubt animating the #navInner div is need)

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