2016-07-27 65 views
0

所以我嘗試使用下面的內容的滑塊菜單。那麼,我已經完成了菜單,並且滑塊可以工作,但右側只有一個很小的空白區域,可以滾動。這真的沒有什麼大不了的,但它確實讓我感到困擾。如果你們可以幫我解決這個問題,那將非常感激。當我擁有一個滑塊時,右側的空白區域

$('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 { 
 
    /* 
 
\t 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

回答

0

我建議你添加以下到你的CSS:

body { 
    overflow-x: hidden; 
} 

通過使隱藏這將簡單的停在x軸的溢出...

因此你會不會能夠滾動,並且無法看到白色空間!

0

這有幾個原因。

  1. contentArea具有1000個像素的固定寬度,請嘗試更改到別的東西,例如100%。這將有助於在較小的屏幕上。

  2. 有一個類text的容器。在大多數瀏覽器上,它的box-sizing默認爲content-box,不包括寬度計算的填充。當容器的寬度設置爲100%並且具有填充時,將在100%之上添加填充。 要包括填充到容器的寬度,這增加了text類樣式:box-sizing: border-box;

$('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; 
 
    box-sizing: border-box; 
 
} 
 
/* 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 { 
 
    /* 
 
\t width: 100%;*/ 
 
    background-color: #333; 
 
} 
 
.contentArea { 
 
    width: 100%; 
 
    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>