试试这个,它使用通过 java sscript 更改 CSS 类触发的 CSS3 过渡:
<html>
<head>
<style>
.message_box_red {
width: 409px;
height: 50px;
border: 0;
margin: 0;
padding: 0;
cursor: pointer;
background: red;
-webkit-transition: all 1s ease-out;
-moz-transition: all 1s ease-out;
-ms-transition: all 1s ease-out;
-o-transition: all 1s ease-out;
transition: all 1s ease-out;
}
.message_box_red.animate {
border: 2px solid;
margin: 1px;
padding: 7px;
width: 409px;
height: 100px;
background: blue;
color: #fff;
}
</style>
<script>
function change_class(did, content) {
var div_change = document.getElementById(did);
div_change.setAttribute("class", "message_box_red animate");
div_change.innerHTML = content;
}
</script>
</head>
<body>
Click on DIV!
<div class="message_box_red" id="commentForm_error_name" onclick="change_class('commentForm_error_name','this is the future content of DIV...');">
</div>
</body>
</html>
现场示例:
http ://simplestudio.rs/yard/div_animate/chng_color.html