HTML5 Loading data-section when click on Navigation link

前端 未结 4 1479
暖寄归人
暖寄归人 2020-12-22 01:50

I am having some road blocks getting this going. I have 4 navigation links and within the content container, I have declared a handful sections and have id tagged them accor

相关标签:
4条回答
  • 2020-12-22 02:02

    You have a typo here (contnet):

    $("#contnet section").fadeIn();
    

    does that fix it?

    Also, you never use the id variable which you have defined.

    0 讨论(0)
  • 2020-12-22 02:09

    This will defiantly work:

    $("a").on("click", function(e) {
        e.preventDefault();
        var sectionID = '#'+ $(this).data("section");
        $("#content section:visible").fadeOut();
        $(sectionID).fadeIn();
    });
    

    SEE WORKING FIDDLE

    0 讨论(0)
  • 2020-12-22 02:16

    Remove '#' in data-section at navigation

    Example:
    data-section="about"

    not "#about"

    0 讨论(0)
  • 2020-12-22 02:18

    This could be work:

    $("a").bind("click", function(e) {
        e.preventDefault();
        var id = $(this).data("section");
          $("#content section:visible").fadeOut();
          $(id).fadeIn();
    });
    
    0 讨论(0)
提交回复
热议问题