博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
css 幻灯片_如何使用HTML,CSS和JavaScript创建幻灯片
阅读量:2519 次
发布时间:2019-05-11

本文共 2555 字,大约阅读时间需要 8 分钟。

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)

            
Slideshow

编写样式以隐藏幻灯片并仅显示一张幻灯片。 (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 wrote  slideshows.forEach(initSlideShow);  function initSlideShow(slideshow) {    var slides = document.querySelectorAll(`#${slideshow.id} [role="list"] .slide`); // Get an array of slides    var index = 0, time = 5000;    slides[index].classList.add('active');          setInterval( () => {      slides[index].classList.remove('active');            //Go over each slide incrementing the index      index++;            // If you go over all slides, restart the index to show the first slide and start again      if (index === slides.length) index = 0;             slides[index].classList.add('active');    }, time);  }

()

翻译自:

css 幻灯片

转载地址:http://wqrwd.baihongyu.com/

你可能感兴趣的文章
fatal error C1853
查看>>
Ural 1001 - Reverse Root
查看>>
玩转webpack之webpack的entry output
查看>>
java 操作mongodb查询条件的常用设置
查看>>
黑马程序员_java基础笔记(02)...java语言基础组成
查看>>
关于缓存击穿
查看>>
对innodb 拷贝文件实现数据库的方式(转)
查看>>
python知识点 2014-07-09
查看>>
FloatingActionButton的一点学习感悟
查看>>
ABAP CDS ON HANA-(10)項目結合して一つ項目として表示
查看>>
网站地址信息
查看>>
产品经理 - 登录 注册
查看>>
小白的python进阶历程------05.占位符
查看>>
CF414BMashmokh and ACMDP
查看>>
Notepad++ 通过g++编译
查看>>
JAVA基础2——类初始化相关执行顺序
查看>>
转:Zend Framework 重定向方法(render, forward, redirect)
查看>>
Linux下查看磁盘与目录的容量——df、du
查看>>
关于日记app的思考
查看>>
使用sencha的cmd创建项目时提示找不到\Sencha\Cmd\repo\.sencha\codegen.json
查看>>