html滚动效果代码

html滚动效果代码

在HTML中创建滚动效果,可以使用CSS的@keyframes规则来定义动画,并结合animation属性来应用这个动画。以下是一个简单的例子,演示了如何使用CSS创建一个水平滚动的效果:

代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>滚动效果示例</title>
<style>
  .scrolling-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: scroll 5s linear infinite;
  }
 
  @keyframes scroll {
    0% {
      transform: translateX(100%);
    }
    100% {
      transform: translateX(-100%);
    }
  }
</style>
</head>
<body>
 
<div class="scrolling-text">
  这是一个滚动的文本效果,它会不断地从右向左滚动。
</div>
 
</body>
</html>
过期时间:永久公开
创建于:2024-03-21 17:55
65