返回列表

CSS3之transform自动复位问题

默认分类 2014/09/13 00:17

我们使用CSS3之transform/-webkit-keyframes实现动画时,动画结束状态不会自动保持。

代码如下:

<!DOCTYPE html>
<html lang="zh-cn" class="no-js">
<head>
<meta http-equiv="Content-Type">
<meta content="text/html; charset=utf-8">
<meta charset="utf-8">
<title>沪江网</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="email=no">
<meta name="author" content="wechat:femvc_com">

<style>
.aa {position:absolute;left:0px;top:0px;z-index:50; }

@-webkit-keyframes 'dddin' {
    0% {
        left: 0px
    }
    100% {
        left: 200px
    }
}
.dddin {
-webkit-animation-name: "dddin";
-webkit-animation-duration: 0.3s;
-webkit-animation-timing-function: ease;
-webkit-animation-iteration-count: 1;
}

</style>
</head>

<body>
    <button class="aa" onclick="this.className+=' dddin'">button</button>
</body>
</html>

需要将动画结束状态放到class中。

代码如下:

<!DOCTYPE html>
<html lang="zh-cn" class="no-js">
<head>
<meta http-equiv="Content-Type">
<meta content="text/html; charset=utf-8">
<meta charset="utf-8">
<title>沪江网</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="email=no">
<meta name="author" content="wechat:femvc_com">

<style>
.aa {position:absolute;left:0px;top:0px;z-index:50; }

@-webkit-keyframes 'dddin' {
    0% {
        left: 0px
    }
    100% {
        left: 200px
    }
}
.dddin {
left: 200px;
-webkit-animation-name: "dddin";
-webkit-animation-duration: 0.3s;
-webkit-animation-timing-function: ease;
-webkit-animation-iteration-count: 1;
}

</style>
</head>

<body>
    <button class="aa" onclick="this.className+=' dddin'">button</button>
</body>
</html>