jQuery基础:$("selector:animated")

1、问题描述:在我之前的影像中,我一直认为$("selector:animated")可以获取所有有效果的元素、今天发现这个只能对那些已经绑定animate方法的元素进行筛选、不能对自定义的效果(例如用setInterval实现的)进行筛选。

2、结果验证:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            margin: 10px;
            border: 1px red solid;
            position: absolute;
            top: 50px;
        }

        #box2{
            top: 300px;
        }
    </style>
</head>
<body>
    <div id="box1"></div>
    <div id="box2"></div>
    <button id="btn">anniu</button>
</body>
<script src="jquery-1.8.3.min.js"></script>
<script type="text/javascript">
    $(function(){

        var index =0;

        $("#box1").animate({
            left: "+=400",
        },5000)

        setInterval(function(){
            index++;
            $("#box2").css({
                left: index*20,
            })
        },100)

        $("#btn").click(function(){
            $("div:animated").css({
                "background-color": "red",
            })
        })
    })
</script>
</html>
posted on 2016-10-04 21:22  花雨伞  阅读(377)  评论(0编辑  收藏  举报