我现在有点陷入困境,我不确定如何在底部的幻灯片中获得这些图像以便顺利过渡,我对编码很新,并且对javascript和javascript知之甚少CSS。我知道HTML的基础。 如果有人能提供一些非常感激的帮助。
我已将代码粘贴到下方。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> EVOLUTION </title>
<style type="text/css">
body {
background-image:url('backgroundimagebase.jpg');
background-size:cover;
background-attachment: fixed
</style>
<style>
.mySlides {display:none}
.w3-left, .w3-right, .w3-badge {cursor:pointer}
.w3-badge {height:13px;width:13px;padding:0}
</style>
<style>
img {
position: absolute;
transition: opacity .5s ease-in;
}
img + img { opacity: 0; }
</style>
<style>
img {
position: absolute;
transition: opacity .5s ease-in;
}
img + img { opacity: 0; }
</style>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<!--slideshow stuff-->
<!--image headings-->
<div class="w3-display-container mySlides">
<a href="file:///C:/Users/Harrison%20Gobey/Desktop/College%20Work/Unit%2028/website/projectwebsite3.html"><img src="pcexclusives.jpg" alt="pcexclusives" style="width:100%" height="768" width="1366"></a>
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">Check out our new range of PC exclusives!
</div>
</div>
<div class="w3-display-container mySlides">
<a href="https://www.polygon.com/2018/6/14/17465314/battlefield-5-women-historical-accuracy-reddit-banned"><img src="battlefieldV.jpg" style="width:100%" height="768" width="1366"></a>
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
Battlefield V panned by fans for historical inaccuracy
</div>
</div>
<div class="w3-display-container mySlides">
<a href="http://www.trustedreviews.com/news/elders-scrolls-6-trailer-release-date-2993132"><img src="bethesdaes6.jpg" style="width:100%" height="768" width="1366"></a>
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
Bethesda officially announce Elder Scrolls 6 at E3 2018
</div>
</div>
<!--image indicator-->
<div class="w3-content w3-display-container">
<div class="w3-center w3-display-bottommiddle" style="width:100%">
<div class="w3-left" onclick="plusDivs(-1)">❮</div>
<div class="w3-right" onclick="plusDivs(1)">❯</div>
<span class="w3-badge demo w3-border" onclick="currentDiv(1)"></span>
<span class="w3-badge demo w3-border" onclick="currentDiv(2)"></span>
<span class="w3-badge demo w3-border" onclick="currentDiv(3)"></span>
</div>
</div>
<script>
var slideIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {slideIndex = 1}
x[slideIndex-1].style.display = "block";
setTimeout(carousel, 4000); // Change image every 4 seconds
}
</script>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length} ;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-white", "");
}
x[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " w3-white";
}
</script>
</body>
</html>
答案 0 :(得分:0)
您的代码存在一些问题。一个是没有开放body
标签,身体的css也没有关闭括号。您的CSS样式中存在重复,并且在您的javascript代码中,您重新声明了相同的变量三次。它应该只声明一次,然后重新使用。你的javascript中的另一个错误是你调用showDivs函数的地方。我将这一行移到了旋转木马功能中。
这是一个jsfiddle我希望你能找到帮助(pix可能不准确,但要记住本地存储的文件只能从你自己的计算机调用 - 最好从服务器指定来源)
拉结
var slideIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {
slideIndex = 1
}
x[slideIndex - 1].style.display = "block";
setTimeout(carousel, 4000); // Change image every 4 seconds
showDivs(slideIndex);
}
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = x.length
};
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex - 1].style.display = "block";
}
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > x.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = x.length
}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-white", "");
}
x[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " w3-white";
}
&#13;
body {
background-image: url('backgroundimagebase.jpg');
background-size: cover;
background-attachment: fixed;
}
.mySlides {
display: none;
}
.w3-left,
.w3-right,
.w3-badge {
cursor: pointer;
}
.w3-badge {
height: 13px;
width: 13px;
padding: 0;
}
img {
position: absolute;
transition: opacity .5s ease-in;
}
img+img {
opacity: 0;
}
&#13;
<link href="https://www.w3schools.com/w3css/4/w3.css" rel="stylesheet" />
<!--slideshow stuff-->
<!--image headings-->
<body>
<div class="w3-display-container mySlides">
<a href="file:///C:/Users/Harrison%20Gobey/Desktop/College%20Work/Unit%2028/website/projectwebsite3.html"><img src="pcexclusives.jpg" alt="pcexclusives" style="width:100%" height="768" width="1366"></a>
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">Check out our new range of PC exclusives!
</div>
</div>
<div class="w3-display-container mySlides">
<a href="https://www.polygon.com/2018/6/14/17465314/battlefield-5-women-historical-accuracy-reddit-banned"><img src="battlefieldV.jpg" style="width:100%" height="768" width="1366"></a>
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
Battlefield V panned by fans for historical inaccuracy
</div>
</div>
<div class="w3-display-container mySlides">
<a href="http://www.trustedreviews.com/news/elders-scrolls-6-trailer-release-date-2993132"><img src="bethesdaes6.jpg" style="width:100%" height="768" width="1366"></a>
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
Bethesda officially announce Elder Scrolls 6 at E3 2018
</div>
</div>
<!--image indicator-->
<div class="w3-content w3-display-container">
<div class="w3-center w3-display-bottommiddle" style="width:100%">
<div class="w3-left" onclick="plusDivs(-1)">❮</div>
<div class="w3-right" onclick="plusDivs(1)">❯</div>
<span class="w3-badge demo w3-border" onclick="currentDiv(1)"></span>
<span class="w3-badge demo w3-border" onclick="currentDiv(2)"></span>
<span class="w3-badge demo w3-border" onclick="currentDiv(3)"></span>
</div>
</div>
</body>
&#13;