jquery toggle(显示/隐藏)基于选择器 [英] jquery toggle (show/hide) based on selector

查看:177
本文介绍了jquery toggle(显示/隐藏)基于选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于jquery创建动画,下面是我的代码;

I want to create animation based on jquery, below is my code;

>items=document.querySelectorAll("#customers td span");
[<span alt=​"  02,Counter,11,2013-04-06 14:​59:​16">​  02​</span>​, <span>​11​</span>​, <span alt=​"  02,Counter,11,2013-04-06 13:​22:​19">​  02​</span>​, <span>​11​</span>​]
>item=items[0]; // it has a parent tag <tr> i want the whole row to blink (both spans)
<span alt=​"  02,Counter,11,2013-04-06 14:​59:​16">​  02​</span>​
>tm=item.attributes.getNamedItem("alt");
alt=​"  02,Counter,11,2013-04-06 14:​59:​16"
>dtm=tm.value.split(',')[3];
"2013-04-06 14:59:16"

/ p>

or in JQuery:

$(document).ready(function() {
    window.setInterval(function(){
        $("#customers, td, #span").each(function(){
            if($(this).children("span").attr("alt")!=null)
                var dt=new Date($(this).children("span").attr("alt").split(",")[3]).getTime();
                    if(dt>$.now()-10*1000){ //am i right here??
                        console.log("animating");
                        $(this).parent().fadeOut("slow");
                        $(this).parent().fadeIn("slow");
                    }        
       });
    },1000);
});

每秒我想检查项目中的每个元素;如果dtm>当前时间-10秒,则它应该在500毫秒后隐藏,并应在500毫秒后显示。

every second i want to check for each element in items; if dtm > current time - 10 seconds, then it should hide after 500 ms and should show after 500ms.

上面的代码只有闪烁一个跨度希望这两个元素都闪烁...这个检查应该每1秒继续。

the code above that i have will only blink one span, i want both of the elements to blink.. and this check should continue each 1 second.

可以帮助我..

谢谢..

推荐答案

下面是我的最终代码:

<script>
$(document).ready(function ($) {
    window.setInterval(function(){
        $("#customers, td, span").each(function(){
            if($(this).children("span").attr("alt")!=null){
                var dt=new Date($(this).children("span").attr("alt").split(",")[3].replace(/-/g,"/")).getTime();
                if(dt>$.now()-20*1000){
                    console.log("animating");
                    $(this).parent().fadeOut(500,"linear");
                    $(this).parent().fadeIn(500,"linear");
                }
            }
        });
    },1100);
});
</script>

这篇关于jquery toggle(显示/隐藏)基于选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆