简体   繁体   English

单击后淡出

[英]fade out after click

I want the same behaviour as stackoverflow's. 我想要与stackoverflow相同的行为。

In SO, after we click the unread inbox, which is red in color and if we click any where else, it fades out. 在SO中,当我们单击未读收件箱时,该收件箱是红色的,如果单击其他任何地方,则它会逐渐消失。

I have this html: 我有这个HTML:

<small class="notifi pull-right">1</small>

And I'm currently doing: 我目前正在做:

    $('small.pull-right').click(function () {
        var that = this;
        $(document).one('click', function () {
            $(that).hide('fade');
        });
    });

But, it isn't working. 但是,它不起作用。 After the <small> is clicked, a dropdown opens. 单击<small>后,将打开一个下拉列表。 Thats fine. 没关系。 After that if a user clicks somewhere else, it should fade out. 之后,如果用户单击其他位置,则它应淡出。

So, what should I? 那我该怎么办

try this 尝试这个

html code HTML代码

<small class="notifi pull-right">1</small>

jQuery jQuery的

   $('.pull-right').click(function () {
        var that = this;
        $(document).one('click', function () {
            $(that).hide('fade');
        });
    });

See DEMO 演示

You also have a typo here: 您在这里也有错别字:

$('small.notify.pull-right')

It has to be 它一定要是

$('small.notifi.pull-right')

Here a running demo: http://jsfiddle.net/Hnz5p/ 这是一个正在运行的演示: http : //jsfiddle.net/Hnz5p/

I would write: 我会写:

var button = $('small.notifi.pull-right');
button.click(function () {
    $(document).one('click', function () {
        button.fadeOut('slow');
    });
});

Try this 尝试这个

Hit Me 打我

$("#smallid").click(function () { $(“#smallid”)。click(function(){

    $("#smallid").fadeOut();
});

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

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