Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内联Javascript计时器_Javascript_Jquery_Css_Html - Fatal编程技术网

内联Javascript计时器

内联Javascript计时器,javascript,jquery,css,html,Javascript,Jquery,Css,Html,我使用jQuery插入html div以通知用户。我需要制作一个内联javascript计时器,在一定时间后关闭通知。这就是div的外观: 给带前缀的div一个id(带有时间戳或一些随机的东西) 在函数add_tab中,调用一个新函数remove_tab,并将生成的id作为其参数 当remove_选项卡运行时,它应该删除通过参数传递的id为的div 成功 无需安装单独的插件或任何东西,您必须借助jquery插件 像 您必须在脚本中下载此JS插件 clock.start(function() {

我使用jQuery插入html div以通知用户。我需要制作一个内联javascript计时器,在一定时间后关闭通知。这就是div的外观:

  • 给带前缀的div一个id(带有时间戳或一些随机的东西)
  • 在函数add_tab中,调用一个新函数remove_tab,并将生成的id作为其参数
  • 当remove_选项卡运行时,它应该删除通过参数传递的id为的div
  • 成功

  • 无需安装单独的插件或任何东西,您必须借助jquery插件

    您必须在脚本中下载此JS插件

    clock.start(function() {
    // this (optional) callback will fire each time the clock flips
    });
    to start timer
    
    clock.stop(function() {
    // this (optional) callback will fire after the clock stops
    
    })); 停止计时器

    clock.setTime(3600);
    clock.setCountdown(true);
    var time  = clock.getTime();
    
    这样你就可以得到你想要的结果

    我做了一个解决方案

    clock.start(function() {
    // this (optional) callback will fire each time the clock flips
    });
    to start timer
    
    clock.stop(function() {
    // this (optional) callback will fire after the clock stops
    

    当您添加要隐藏的制表符标记时,可以在数据时间属性上显示要隐藏的时间

    代码

    addtab = setInterval( add_tab, 3000 );
    
    
    function add_tab(){
    var timeToHide = 6500;
    
    var tab = $('<div class="rightnot-tab"><div class="rightnot-tab-image"><img src="http://movies.dosthana.com/sites/default/files/image-gallery/Bradley%20Cooper%20Stills.jpg" width="60" height="60"/></div><div class="rightnot-tab-text"><a href="#">Bradley Cooper</a> added you as a friend</div><div class="rightnot-tab-close"><img src="https://cdn1.iconfinder.com/data/icons/lynx/22x22/actions/dialog-close.png" width="22" height="22"/></div></div>');
    
    $("#rightnot").hide().prepend(tab).fadeIn(500)
    
    setTimeout(function(){
       removeTab(tab);
    
    },timeToHide);
    
    
    
    $('.rightnot-tab-close').click(function(){
        removeTab($(this).parent());    
        })
    
    }
    
    function removeTab( tab ) { //you can change the implementation
         $(tab).animate({ opacity: 0 }, function(){
            $(tab).slideUp(500, function(){
                $(tab).remove();
            });    
        });
    
    }
    
    addtab=setInterval(add_tab,3000);
    函数add_tab(){
    var timeToHide=6500;
    var tab=$(“将您添加为朋友”);
    $(“#rightnot”).hide().prepend(制表符).fadeIn(500)
    setTimeout(函数(){
    移除选项卡(选项卡);
    },timeToHide);
    $('.rightnot制表符关闭')。单击(函数(){
    removeTab($(this.parent());
    })
    }
    函数removeTab(tab){//您可以更改实现
    $(tab).animate({opacity:0},function()){
    $(tab).slideUp(500,函数(){
    $(制表符).remove();
    });    
    });
    }
    
    您真正需要什么?这是不可理解的,您应该顺便在问题中添加相关代码,而不仅仅是链接到演示。只是一个建议-当您在notify div上悬停时,您可能需要停止/暂停自动关闭计时器:)非常感谢这确实有效:)