简体   繁体   English

当用户单击菜单中的项目时,jQuery不会消失吗?

[英]jQuery won't fade when user clicks and item in menu?

I have managed to make my webpage fade to a set page when a user clicks on the main menu but when the user clicks on an item in the menu on the page s/he has just entered it will not fade back into the page the user wants to access? 当用户单击主菜单时,我设法使网页淡入设置页面,但是当用户单击页面上菜单中的项目时(他/他刚刚输入),它不会退回到用户页面中要访问?

There is a lot of code so here's a link to the site: http://www.penguinie.co.uk here's a JSFiddle but it may not convey the way iw ant it to work 有很多代码,因此这里是该站点的链接: http ://www.penguinie.co.uk这是一个JSFiddle,但它可能无法传达其工作方式

http://jsfiddle.net/NxAzu/ http://jsfiddle.net/NxAzu/

There is a main.css file, a fade.js file and the index.html file. I also use animate.css.

I asked a similar question here about how to make the links actually work: https://stackoverflow.com/questions/19776289/jquery-fade-in-and-out-isnt-working 我在这里问了一个类似的问题,关于如何使链接真正起作用: https : //stackoverflow.com/questions/19776289/jquery-fade-in-and-out-isnt-working

Any and all help appreciated, thanks. 任何和所有帮助表示赞赏,谢谢。

It looks like most of the jQuery + animation CSS that you have isn't really necessary for what you're trying to do ( if I'm correctly grasping the concept ). 看起来您拥有的大多数jQuery +动画CSS并不是真正想要执行的操作(如果我正确地理解了这个概念)。

Remove the jQuery code as well as the animate.css that you currently have and try plugging this in: 删除jQuery代码以及当前拥有的animate.css,然后尝试将其插入:

$('a[href^="#"]').on('click', function(){

    // Cache
    var _this = $(this);

    // Get the section name that you want to show
    var section_to_show = $(_this.prop('hash'));

    // Hide all other sections except the one you want to show
    // but make sure it's not currently being animated
    _this.closest('section').not(':animated').animate({
        'margin-top': '-100px', 
        opacity: 0
    }, 750, function() {

        // Hide the current element so it can be
        // faded in next time it's called
        $(this).hide();

        // Fade in the section that you wanted 
        section_to_show.css({ 
            opacity: 1,
            'margin-top': '0'
        }).fadeIn(750);

    });

});

Since you have all of your sections named the same as the hash in each link, you can just call the hash value from the link that you clicked on, fade out the current section (with a little slide up + fadeout animation ) and then fade in the new for each click. 由于所有部分的名称都与每个链接中的哈希相同,因此您只需从单击的链接中调用哈希值,淡出当前部分(略微向上滑动+淡出动画),然后淡出即可在新的每次点击中。

Finally, remove the .animated .fadeInDown classes from the #start section as it seems to throw off the animation: 最后,从#start部分中删除.animated .fadeInDown类,因为它似乎会抛出动画:

<section id="start" class="start">

PS You may want to move the navigation into it's own container outside of all of the fancy section animations to avoid creating markup for the same menu on every section. PS您可能希望将导航移到所有花式部分动画之外的自己的容器中,以避免在每个部分上为同一菜单创建标记。 Just a suggestion. 只是一个建议。

Here's a fiddle example: http://jsfiddle.net/aPPYT/3/ 这是一个小提琴示例: http : //jsfiddle.net/aPPYT/3/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM