html - 是否可以仅使用 html/css 创建背景图像 slider

标签 html css

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 6 年前

我想在我的网站上有一个 slider ,到目前为止,我只能使用实际的 <img> 来实现它。我知道可以让您的图片淡入然后淡出,而不是背景图片,但我想知道是否可以让您的背景图片从页面上滑出。

最佳答案

您可以使用 CSS3 的多背景支持并使用标准动画进行滑动:

.slideshow {
  width: 600px;
  height: 400px;
  border: 1px solid #999;
  background: url(http://lorempixel.com/600/400/sports?_=1) 0 0 no-repeat,
    url(http://loremflickr.com/600/400/sports?_=2) 600px 0 no-repeat,
    url(http://loremflickr.com/600/400/sports?_=3) 1200px 0 no-repeat,
    url(http://loremflickr.com/600/400/sports?_=4) 1800px 0 no-repeat;
  animation: slide-right 15s forwards 1s;
}
@keyframes slide-right{
  0% {
    background-position: 0 0, 600px 0, 1200px 0, 1800px 0
  }
  16%, 33% {
    background-position: -600px 0, 0 0, 600px 0, 1200px 0
  }
  49%, 66% {
    background-position: -1200px 0, -600px 0, 0 0, 600px 0
  }
  85%, 100% {
    background-position: -1800px 0, -1200px 0, -600px 0, 0 0
  }
}
<div class="slideshow"></div>

关于html - 是否可以仅使用 html/css 创建背景图像 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38235029/

上一篇:php - 仅在插件页面 WordPress 上显示样式表

下一篇:html - 如何使用 CSS 将 "crop"矩形图像变成正方形?

相关文章:

java - Jsoup.clean() 未关闭并打开标签

javascript - 如果今天是会计年度的最后一天,则从下拉菜单中删除当前年份

html - 如何使用纯 CSS 创建动画表单占位符

html - 如何将整个 html 主体对齐到中心?

css - Angular Material md-tab 滚动内容

css - 加载 gruntfile.js 任务时如何修复 'SyntaxError: Unexpected identifier Warning: Task "sass“未找到”?

javascript - JQuery 根据当前选择的文本输入更改 TR 背景颜色

html - 带有 Logo 的 Bootstrap 导航栏

html - 使用粘性图像时删除页面底部的空白

javascript - jS居中功能不适用于页面加载中的一个元素,只需调整大小