微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在调整DIV大小时需要平滑动画 – JavaScript

当我在DIV上空盘旋时,它的高度和宽度都会增加,但我不知道如何让它更加平滑,而不是一次调整大小
function chg()
{
  document.getElementById("d1").innerHTML="Great Job!";
  document.getElementById("d1").style.width="300px";
  document.getElementById("d1").style.height="200px";
}

function chg2()
{
  document.getElementById("d1").innerHTML="Hover Over Me!";
  document.getElementById("d1").style.width="230px";
  document.getElementById("d1").style.height="160px";
}
div
{
  background-color:RGB(177,0);
  color:white;
  font-size:large;
  height:160px;
  width:230px;
  text-align:center;
  line-height:150px;
}
<!DOCTYPE html>
<html>
<body>
<div onmouSEOver="chg()" onmouSEOut="chg2()" id="d1">Hover Over Me!</div>
</body>
</html>

解决方法

说明

你应该看看CSS3中的过渡属性.

资源

有关更多信息,请查看以下链接

> CSS3 Transitions
> Using CSS transitions

function chg() {
  document.getElementById("d1").innerHTML = "Great Job!";
  document.getElementById("d1").style.width = "300px";
  document.getElementById("d1").style.height = "200px";
}

function chg2() {
  document.getElementById("d1").innerHTML = "Hover Over Me!";
  document.getElementById("d1").style.width = "230px";
  document.getElementById("d1").style.height = "160px";
}
div {
  background-color: RGB(177,0);
  color: white;
  font-size: large;
  height: 160px;
  width: 230px;
  text-align: center;
  line-height: 150px;
  transition: all .5s linear;
}
<div onmouSEOver="chg()" onmouSEOut="chg2()" id="d1">Hover Over Me!</div>

原文地址:https://www.jb51.cc/css/215386.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。