因此,我试图在其下具有内容的滑块菜单。好吧,我已经完成了所有菜单,并且滑块也起作用了,但是右侧只有很小的空白可以滚动。这确实没什么大不了的,但是确实使我烦恼。如果你们能帮助我解决这个问题,将不胜感激。



$('span.nav-btn').click(function() {


  $(window).resize(function() {
    if ($(window).width() > 1000) {

      $('ul.nav').removeAttr('style');
    }
  })
});
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";
}

/* Slideshow container */

.slideshow-container {
  width: 100%;
  position: relative;
}
/* Next & previous buttons */

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 0;
  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;
}
/* 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: 13px;
  width: 13px;
  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
  }
}
html,
body {
  padding: 0;
  margin: 0;
  font-family: "Roboto", sans-serif;
}
.nav {
  background-color: #E74C3C;
  color: #fff;
  margin: 0;
  list-style: none;
  height: 100%;
}
.nav > li {
  display: inline-block;
}
.nav > li > a {
  text-decoration: none;
  font-size: 40px;
  color: #fff;
  padding-left: 10px;
  padding-right: 10px;
  padding-bottom: 25px;
  padding-top: 15px;
  font-weight: bold;
}
.nav li:hover {
  background-color: rgb(255, 0, 0);
  margin: 0;
  padding;
  0;
}
h2 {
  font-size: 100px;
}
.content {
  /*
	width: 100%;*/
  background-color: #333;
}
.contentArea {
  width: 1000px;
  background-color: #fff;
}
@media (max-width: 1000px) {
  .nav {
    text-align: left;
    display: none;
  }
  .nav > li {
    display: block;
  }
  .nav > li > a {
    font-size: 80px;
    line-height: 150px;
  }
  .nav-btn {
    display: block;
    background-color: #333;
    color: #FFF;
    font-size: 150px;
    text-align: center;
    cursor: pointer;
    height: 200px;
  }
  .nav-btn:before {
    content: "Menu";
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div class="container">
  <!-- Begin Navigation -->
  <nav>
    <span class="nav-btn"></span>
    <ul class="nav">
      <li><a href="#home">HOME</a>
      </li>
      <li><a href="#about">ABOUT</a>
      </li>
      <li><a href="#projects">PROJECTS</a>
      </li>
      <li><a href="#videos">VIDEOS</a>
      </li>
      <li><a href="#contact">CONTACT</a>
      </li>
    </ul>
  </nav>
  <!-- End Navigation -->

  <!-- Begin Content -->
  <div class="content">

    <div class="slideshow-container">
      <div class="mySlides fade">
        <div class="numbertext">1 / 3</div>
        <img src="http://www.placecage.com/c/460/460" style="width:100%">
        <div class="text">Caption Text</div>
      </div>
      <div class="mySlides fade">
        <div class="numbertext">2 / 3</div>
        <img src="http://www.placecage.com/g/460/460" style="width:100%">
        <div class="text">Caption Two</div>
      </div>
      <div class="mySlides fade">
        <div class="numbertext">3 / 3</div>
        <img src="http://www.placecage.com/460/460" style="width:100%">
        <div class="text">Caption Three</div>
      </div>
      <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
      <a class="next" onclick="plusSlides(1)">&#10095;</a>
    </div>
    <br>
    <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>

    <!-- Begin Content Area -->
    <div class="contentArea">
      <p>hi</p>
    </div>
    <!-- End Content Area -->
  </div>
  <!-- End Content -->
</div>





我将滑块css和主css放在不同的文件中,因为我想保持它的美观和整洁。

另外,如果您想查看该站点,也可以在这里访问。 jumpymotionpictures.net

最佳答案

我建议您将以下内容添加到CSS中:

body {
  overflow-x: hidden;
}


通过隐藏它可以简单地停止x轴上的溢出...

因此,您将无法滚动,也无法看到空白!

07-25 23:09
查看更多