css 幻灯片

A web slideshow is a sequence of images or text that consists of showing one element of the sequence in a certain time interval.

网络幻灯片是一系列图像或文本,包括在一定时间间隔内显示序列中的一个元素。

For this tutorial you can create a slideshow by following these simple steps:

对于本教程,您可以按照以下简单步骤创建幻灯片:

写一些标记 (Write some markup)

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Slideshow</title><link rel="stylesheet" href="style.css"></head><body><div id="slideshow-example" data-component="slideshow"><div role="list"><div class="slide"><img src="" alt=""></div><div class="slide"><img src="" alt=""></div><div class="slide"><img src="" alt=""></div></div></div><script src="slideshow.js"></script></body></html>

编写样式以隐藏幻灯片并仅显示一张幻灯片。 (Write styles to hide slides and show only one slide.)

To hide the slides you have to give them a default style. It'll dictate that you only show one slide if it is active or if you want to show it.

要隐藏幻灯片,您必须为其提供默认样式。 它将指示您仅显示一张处于活动状态或想要显示的幻灯片。

[data-component="slideshow"] .slide {display: none;}[data-component="slideshow"] .slide.active {display: block;}

每隔一段时间更改幻灯片。 (Change the slides in a time interval.)

The first step to changing which slides show is to select the slide wrapper(s) and then its slides.

更改幻灯片显示的第一步是选择幻灯片包装,然后选择其幻灯片。

When you select the slides you have to go over each slide and add or remove an active class depending on the slide that you want to show. Then just repeat the process for a certain time interval.

选择幻灯片时,您必须经过每张幻灯片,然后根据要显示的幻灯片添加或删除活动的班级。 然后,只需在一定时间间隔内重复该过程即可。

Keep it in mind that when you remove an active class from a slide, you are hiding it because of the styles defined in the previous step. But when you add an active class to the slide, you are overwritring the style display:none to display:block , so the slide will show to the users.

请记住,从幻灯片中删除活动类时,由于上一步中定义的样式,您将其隐藏。 但是,当您向幻灯片中添加活动类时,您将覆盖样式display:none to display:block ,因此幻灯片将向用户显示。

var slideshows = document.querySelectorAll('[data-component="slideshow"]');// Apply to all slideshows that you define with the markup wroteslideshows.forEach(initSlideShow);function initSlideShow(slideshow) {var slides = document.querySelectorAll(`#${slideshow.id} [role="list"] .slide`); // Get an array of slidesvar index = 0, time = 5000;slides[index].classList.add('active');  setInterval( () => {slides[index].classList.remove('active');//Go over each slide incrementing the indexindex++;// If you go over all slides, restart the index to show the first slide and start againif (index === slides.length) index = 0; slides[index].classList.add('active');}, time);}

本教程后面的Codepen示例 (Codepen example following this tutorial)

翻译自: https://www.freecodecamp.org/news/how-to-create-a-slideshow/

css 幻灯片

css 幻灯片_如何使用HTML,CSS和JavaScript创建幻灯片相关推荐

  1. css网格_我如何记住CSS网格属性

    css网格 The syntax for CSS Grid is foreign and hard to remember. But if you can't remember CSS Grid's ...

  2. 解释如何优化css选择器_购物车解释了CSS选择器

    解释如何优化css选择器 by Kevin Kononenko 凯文·科诺年科(Kevin Kononenko) 购物车解释了CSS选择器 (CSS Selectors Explained By Go ...

  3. css 毛玻璃_前端开发,CSS的常用套路附demo的效果实现与源码)

    前言 本文是笔者写CSS时常用的套路.不论效果再怎么华丽,万变不离其宗. 1.交错动画 有时候,我们需要给多个元素添加同一个动画,播放后,不难发现它们会一起运动,一起结束,这样就会显得很平淡无奇.那么 ...

  4. css 闪光_闪光VS。 CSS / HTML:您会选择哪个?

    css 闪光 Macromedia Flash. It's one of the most controversial products in the Web development world. M ...

  5. bootstrap起步 全局css样式概览 全局css样式_栅格 全局css样式_排版

    http://www.bootcss.com/基本模板 https://v3.bootcss.com/getting-started/#template bootstrap起步 <!DOCTYP ...

  6. 鼠标指向变成英文导航(CSS)_网页代码站(www.webdm.cn)

    1 <title>鼠标指向变成英文导航(CSS)_网页代码站(www.webdm.cn)</title> 2 <style type="text/css&quo ...

  7. css 手风琴_如何创建基于CSS的内容手风琴

    在今天的教程中,我们将学习如何仅使用CSS3即可创建水平和垂直内容手风琴 . 有很多jQuery插件可以为您完成这项工作,但是如果访问者关闭了Javascript,该怎么办,那么手风琴将无法正常工作. ...

  8. 传智播客_急先锋_html、css、js_郝强勇老师

    传智播客_急先锋_html.css.js_郝强勇老师 我的GitHub地址:https://github.com/heizemingjun 我的博客园地址:http://www.cnblogs.com ...

  9. css案例_下拉三角翻转

    css案例_下拉三角翻转 css案例_下拉三角翻转常见于 下拉导航 .表单下拉多选 等场景. 原理:三角可以看成是一个只具有右边框和底部边框的方形盒子通过 transform: rotate(45de ...

最新文章

  1. 权威发布 |《科学美国人》:2018全球十大新兴技术
  2. 我国人工智能专利申请量去年超3万件,广东领先
  3. javascript里的post和get有什么区别
  4. 【收藏】win10将wsl升级到wsl2
  5. c语言中赋予从2开始的偶数,2013年计算机二级C语言上机试题三十二及答案
  6. 计算机缺考学校知道吗,计算机二级机考缺考成绩单会不会显示缺考啊
  7. 计算机系统结构综合课程设计报告,计算机系统结构课程设计报告书.doc
  8. 南京大学信号与系统851考研上岸经验分享
  9. 刷访问量新招[流量精灵]
  10. 15-构造函数及原型
  11. 鸿蒙系统如何开启快捷方式,鸿蒙系统功能介绍-华为鸿蒙系统功能详细介绍 - 系统家园...
  12. 1:使用递归函数计算1到n之和
  13. CCS Uniflash烧写CC3200开发板的简易操作笔记
  14. 【C++标准头文件】<string>
  15. 选C++还是选Java,过来人给你一个建议
  16. ubuntu18.04下复现 singleshotpose(yolo-6D) 源代码复现
  17. 基于SSM的图书馆座位预约管理系统
  18. 海纳百川 有容乃大, 壁立千仞 无欲则刚
  19. 协卡助手无法卸载的解决办法
  20. 详解数据架构的七类视图(多图+案例)

热门文章

  1. 信号 09 | 信号概念
  2. css知识笔记(一)——基础知识、选择器、元素分类
  3. MapXtreme2004 vs2005的官方回答
  4. spark集群配置以及java操作spark小demo
  5. 安全开发 | 如何让Django框架中的CSRF_Token的值每次请求都不一样
  6. 字符串、指针、引用、数组基础
  7. spring配置文件注解方式引入的两种方式
  8. 作业二:个人博客作业内容:需求分析
  9. [转载]UEditor报错TypeError: me.body is undefined
  10. 【转】测试过程管理案例6---如何做项目的测试经理?