简体   繁体   English

当单击Facebook时,Facebook如何切换其通知中心图标以显示带有通知的各个DIV?

[英]How does Facebook toggle its notification center icons to display the respective DIVs with the notifications when clicked?

How does Facebook toggle its notification center icons to display the respective DIVs with the notifications when clicked? 当单击Facebook时,Facebook如何切换其通知中心图标以显示带有通知的各个DIV?

All of you have at-least interacted with the Facebook notifications center on the top left near the logo on the Facebook website. 所有人至少与Facebook网站徽标附近左上方的Facebook通知中心进行了交互。 How do they workout that?? 他们如何锻炼?

This is the Image below will illustrate the Facebook notification center I am talking about 这是下图,将说明我正在谈论的Facebook通知中心 FB_NC切换

This is my sample code I was using to workout that.. 这是我用来锻炼的示例代码。

    <style>
        div, a {
            display: block;
        }

        body {
            width: 500px;
            margin: 100px auto;
        }

        a {
            border: 1px solid #ccc;  
            background: #ececec;  
            -webkit-border-radius: 3px;  
            padding: 5px 20px;  
            text-align: center;
            color: red;
            text-decoration: none;
        }

        #one {
            margin-bottom: 30px;
        }

        .dn_js {
            display: none;
        }

        .db_js {
            display: block;
        }

    </style>

    <div class="wrap">
        <div id="one">
            <a href="#" data-open="frdz" class="aTggl active">Friends</a>
            <div id="frdz" class="innerWrap dn_js">Mike</div>
        </div>
        <div id="two">
            <a href="#" data-open="Ntfn" class="aTggl">Noticiations</a>
            <div id="Ntfn" class="innerWrap dn_js">Peter</div>
        </div>
    </div>

Here is the JS 这是JS

    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".aTggl").on("click", function(e) {
                e.preventDefault();
                var $this = $(this);

                $(".active").removeClass("active");

                $this.addClass("active").parent().siblings().children(".innerWrap").addClass("dn_js");

                var content_show = $(this).data("open");
                $("#"+content_show).addClass("db_js"); 
            });
        });
    </script>

After doing some small reading reading I have tried out writing some code and it does work and kind of satisfy what my question was all about. 经过一番阅读后,我尝试编写一些代码,它确实有效并且可以满足我的问题。 If ypu guys don't mind, you can look through my code and tell me what to improve, add or remove. 如果ypu家伙不介意,您可以浏览我的代码并告诉我要改进,添加或删除的内容。

Here is the jsFiddle Demo . 这是jsFiddle演示 Thank you. 谢谢。

Here is also the code from the above demo. 这也是上述演示的代码。

<div id="nc_wrap">
    <div class="one nc_node"> 
      <a class="node_link" data-nc="frd_rqst">Friend Requests</a>
      <div id="frd_rqst" class="ncInnerWrap dn_js">F_R Notfz</div>
    </div>

    <div class="two nc_node">
      <a class="node_link" data-nc="msg_nc">Messages</a>
      <div id="msg_nc" class="ncInnerWrap dn_js">Msg Notfz</div>
    </div>
</div>



     #nc_wrap {
    display:block;
    width:100%;
    height:40px
}
       .one, .two {
    display:inline-block;
    width:40%;
    height:100%;
    float:left;
    background-color:#ddd
}
.one a, .two a {
    display:block;
    text-align:center;
    line-height:100%;
    height:100%;
    padding:0;
    margin:0;
    cursor:pointer;
}
.one {
    margin-right: 5%;
}
.activeNC {
    background-color: red;
}
.dn_js {
    display:none;
}
.db_js {
    display:block;
}

        $(document).ready(function () {
    $(".nc_node").on("click", ".node_link", function (event) {
        event.preventDefault();
        var $this = $(this);
        var nc_panel = $("#" + $this.data("nc"));

        $('.nc_node a').not($this).removeClass('activeNC').next(".ncInnerWrap").removeClass("db_js").addClass("dn_js");
        //$($this).stop(true, true).toggleClass("activeNC");
        $this.toggleClass("activeNC").next(".ncInnerWrap").toggleClass("db_js dn_js");
    });

    /*$(this).on("click", function(){
        $(".node_link").removeClass("activeNC");

        return false;
    });
    */
});

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

相关问题 像Facebook通知中心一样,如何切换“ a”标签元素以显示隐藏的DIV - How to Toggle “a” tag elements to show hidden DIVs just like the Facebook notification center 单击相应链接时如何使用jQuery将标签更改为文本字段? - How to change a label to textfield with jQuery when its respective link is clicked? 悬停并单击相应的div时如何显示图像 - How to display an image when hover and clicked on the respective div 单击网页时如何获取相应的 HTML 元素及其索引? - How to get the respective HTML element and its index when clicked on a web page? 切换按钮出现但点击时不切换 - Toggle button appears but does not toggle when clicked 单击时如何在不更改图像位置的情况下在相应图像下方显示文本? - how to display text below the respective image when it is clicked with out changing the position of the images? 单击按钮时隐藏 div 并显示 div - Hide divs and display div when button clicked 单击另一个div时显示隐藏的div - display hidden divs when another div is clicked 单击锚点时显示更多Divs? - Display More Divs when Anchor is Clicked? 单击文本时如何在文本上添加类,单击另一图像时如何将其删除,并与其他图像文本相同 - How to add a class on text when clicked to its respective image and remove it when click at another image and do the same with other image text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM