javascript - 基于选择器的 jquery 切换(显示/隐藏)

标签 javascript jquery css css-selectors

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

>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"

或者在 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 毫秒后显示。

我上面的代码只会闪烁一个跨度,我希望两个元素都闪烁..并且此检查应该每 1 秒继续一次。

谁能帮帮我..

谢谢..

最佳答案

下面是我的最终代码;

<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>

关于javascript - 基于选择器的 jquery 切换(显示/隐藏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15850236/

相关文章:

javascript - 再次调用构造函数会抛出 Typerror : is not a constructor

javascript - 通过升级保存 HTML5 Canvas

javascript - 我想创建自己的标签,例如 <store></store>、<market></market>

html - 如何最小化 html 表格中的列宽?

CSS悬停下拉问题

javascript - 从 Chrome 扩展程序中的 URL 自动填充

javascript - apply javascript 函数有什么作用以及何时使用它?

jQuery 假元素悬停状态

javascript - 使用进度条添加短信

html - 增加 <td> 的宽度