如何创建 - 报价幻灯片
了解如何使用 CSS 和 JavaScript 创建引号幻灯片。
报价幻灯片
创建报价幻灯片
步骤 1) 添加 HTML:
实例
<!-- 幻灯片容器 -->
<div class="slideshow-container">
<!-- 全宽幻灯片 -->
<div class="mySlides">
<q>I love you the more in that I believe you had liked me for my own sake and
for nothing else</q>
<p class="author">- John Keats</p>
</div>
<div class="mySlides">
<q>But man
is not made for defeat. A man can be destroyed but not defeated.</q>
<p class="author">- Ernest Hemingway</p>
</div>
<div
class="mySlides">
<q>I have not failed. I've just found
10,000 ways that won't work.</q>
<p class="author">-
Thomas A. Edison</p>
</div>
<!-- Next/prev buttons -->
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a
class="next" onclick="plusSlides(1)">❯</a>
</div>
<!--
Dots/bullets/indicators -->
<div class="dot-container">
<span
class="dot" onclick="currentSlide(1)"></span>
<span class="dot"
onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
步骤 2) 添加 CSS:
为幻灯片、按钮、圆点等设置样式:
实例
/* 幻灯片容器 */
.slideshow-container {
position:
relative;
background: #f1f1f1f1;
}
/* 幻灯片 */
.mySlides {
display: none;
padding: 80px;
text-align: center;
}
/* Next & previous 按钮 */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -30px;
padding: 16px;
color: #888;
font-weight: bold;
font-size: 20px;
border-radius: 0 3px 3px 0;
user-select:
none;
}
/* 将 "next button" 定位到右侧 */
.next {
position: absolute;
right: 0;
border-radius: 3px 0 0 3px;
}
/* 悬停时,添加一点透视的黑色背景颜色 */
.prev:hover,
.next:hover {
background-color: rgba(0,0,0,0.8);
color:
white;
}
/* 点/项目符号/指示器容器 */
.dot-container {
text-align: center;
padding: 20px;
background: #ddd;
}
/* 点/项目符号/指标 */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display:
inline-block;
transition: background-color 0.6s ease;
}
/* 为活动点/圆圈添加背景颜色 */
.active, .dot:hover {
background-color: #717171;
}
/* 为所有引号添加斜体字体样式 */
q {font-style: italic;}
/* 为作者添加蓝色 */
.author {color: cornflowerblue;}
步骤 3) 添加 JavaScript:
实例
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var
i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n >
slides.length) {slideIndex = 1}
if (n < 1) {slideIndex
= slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className
= dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className
+= " active";
}
亲自试一试 »
提示: 另请查看 如何 - 图片幻灯片 和 如何 - 灯箱。