gpt4 book ai didi

javascript - ASP>NET MVC 5 中的幻灯片

转载 作者:行者123 更新时间:2023-11-27 23:20:10 25 4
gpt4 key购买 nike

对于我的 asp.net mvc 5 应用程序,我遵循了 w3school.com 的幻灯片教程 (https://www.w3schools.com/howto/howto_js_slideshow.asp)。我遇到的问题是当我启动应用程序时。幻灯片显示然后消失得非常快,图片永远不会停留。我想我已经将问题缩小到 css,但我无法弄清楚为什么图片会显示然后很快消失并且再也不会回来。非常感谢任何帮助,谢谢。

我已经尝试注释掉 css 的各个部分并更改一些值,但都没有解决问题。我调试了 javascript,它看起来很好。该索引似乎也没有引起任何问题。我唯一的想法是它必须是 css。

Javascript:

var slideIndex = 1;
showSlides(slideIndex);

// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}

// Thumbnail image controls
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";
}

CSS:

body {
padding-top: 50px;
padding-bottom: 20px;

}

/* Set padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}

/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
*/
.dl-horizontal dt {
white-space: normal;
}

/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
max-width: 280px;
}

/* Fixed footer. */
footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
text-align: center;
background-color: #222;
color: #9d9d9d;
}

body .bodyDiv {
text-align: center;
font-family: Impact, Times New Roman, Times, serif;
font-size: 100px;
color: #222;
text-shadow: 5px 5px #9d9d9d;
}

/* SlideShow Css. */
* {
box-sizing: border-box
}

/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}

/* Hide the images by default
.mySlides {
display: none;
}*/

/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}

/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover, .next:hover {
background-color: rgba(0,0,0,0.8);
}

/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

/* The dots/bullets/indicators */
.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;
}

/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}

@-webkit-keyframes fade {
from {
opacity: .4
}

to {
opacity: 1
}
}

@keyframes fade {
from {
opacity: .4
}

to {
opacity: 1
}
}

索引 View :

@{
ViewBag.Title = "Home Page";
Layout = "~/Views/Shared/_Layout.cshtml";
}

@Scripts.Render("~/Scripts/SlideShow")
<!-- SlideShow. -->
<!-- Slideshow container -->
<div class="slideshow-container">

<!-- Full-width images with number and caption text -->
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>

<img src="~/Content/Patern_test.jpg" style="width:100%">

<div class="text">Caption Text</div>
</div>

<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="~/Content/Patern_test.jpg" style="width:100%">
<div class="text">Caption Two</div>
</div>

<div class="mySlides fade">
<div class="~/Content/Patern_test.jpg">3 / 3</div>
<img src="~/Content/Patern_test.jpg" style="width:100%">
<div class="text">Caption Three</div>
</div>

<!-- Next and previous buttons -->
<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>
<br>

<!-- The dots/circles -->
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>

<body>
<div class="bodyDiv">
Welcome To KrugDevelopment
</div>
</body>

最佳答案

我不明白为什么要将 html 元素放在 body 标签之外,但是,这个问题与不透明度和动画有关,所以:

解决方案 1:尝试将其添加到您的 CSS 中:

.mySlides {
opacity:0;
}

解决方案 2:尝试在页面加载时隐藏幻灯片

 .mySlides {
display: none;
}

关于javascript - ASP>NET MVC 5 中的幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58053012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com