jQuery-animate方法设置和执行动画

2019-10-16  本文已影响0人  手指乐
<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>test</title>
    <style>
        @keyframes my-animation {
            0% {
                color: red;
            }
            50% {
                color: green;
            }
            100% {
                color: blue;
            }
        }
        
        .animtest {
            animation: my-animation 3s linear;
        }
    </style>
    <script>
        function bgAnim() {
            document.getElementById("myanim").classList.add("animtest")
        }
    </script>
</head>

<body>

    <div>
        <button onclick="bgAnim()">test</button>
        <p id="myanim">animation test</p>
    </div>

</body>

</html>

元素会在设置class的时候执行一次动画

$("button").click(function(){
    $("#box").animate({height:"300px"});
});

查看效果

(selector).animate({styles},speed,easing,callback)

styles就是需要控制的css样式,可以是以下值:

可以应用动画的属性:

backgroundPositionX
backgroundPositionY
borderWidth
borderBottomWidth
borderLeftWidth
borderRightWidth
borderTopWidth
borderSpacing
margin
marginBottom
marginLeft
marginRight
marginTop
outlineWidth
padding
paddingBottom
paddingLeft
paddingRight
paddingTop
height
width
maxHeight
maxWidth
minHeight
minWidth
fontSize
bottom
left
right
top
letterSpacing
wordSpacing
lineHeight
textIndent

styles是必需的参数,其他可选,比如速度speed,会有一个默认速度,单位毫秒

上一篇 下一篇

猜你喜欢

热点阅读