我有一些電影我想要在我的網站上顯示一個水平的,可滾動的div。 因爲我刪除了滾動條,用戶不能再滾動,這就是爲什麼我添加了兩個按鈕。一個按鈕向右移動,一個按鈕向左移動。JavaScript滾動按鈕;可以根據需要經常重複
問題是,按鈕可以按照需要經常按下。所以電影將不會再顯示,因爲通過JavaScript添加了保證金。
我該如何解決這個問題? 我想禁用左鍵,當到達開始時,我想禁用右鍵,當到達結束時。
$('#right-button').click(function() {
\t \t event.preventDefault();
\t \t $('.movie-scroll').animate({
\t \t \t \t marginLeft: "-=200px"
\t \t }, "fast");
});
$('#left-button').click(function() {
\t \t event.preventDefault();
\t \t $('.movie-scroll').animate({
\t \t \t \t marginLeft: "+=200px"
\t \t }, "fast");
});
::-webkit-scrollbar {
\t display: none;
}
.sc_content {
\t overflow-y: scroll;
}
.title_home {
\t font-size: 18px;
\t margin: 30px 0px -10px 30px;
}
.movie-scroll {
\t height: 300px;
\t white-space: nowrap;
\t overflow-x: scroll;
\t margin-right: 30px;
}
.thumbnail-movie-box {
\t width: 130px;
\t margin: 30px 0px 0px 30px;
\t display: inline-block;
}
.thumbnail-movie-content {
\t display: block;
\t position: relative;
}
.thumbnail-movie-poster {
\t width: 130px;
\t height: 195px;
}
.thumbnail-movie-title {
font-size: 12px;
font-weight: bold;
\t margin: 5px 0px 10px 0px;
\t white-space: nowrap;
\t overflow: hidden;
\t text-overflow: ellipsis;
}
.thumbnail-movie-year {
\t font-size: 12px;
\t margin: -5px 10px 10px 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div class="sc_content">
<h1 class="title_home">Movies</h1>
<a href="#" id="left-button">Left</a>
<div class="movie-scroll">
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
<div class="thumbnail-movie-box">
<a href="">
<div class="thumbnail-movie-content">
<img class="thumbnail-movie-poster" src="https://image.tmdb.org/t/p/w500/ijoPd2gdt8jW982fGemySKDOGtv.jpg">
</div>
</a>
<a href="">
<p class="thumbnail-movie-title">Split</p>
</a>
<p class="thumbnail-movie-year">2016</p>
</div>
</div>
<a href="#" id="right-button">Right</a>
這裏是一個小提琴:https://jsfiddle.net/qynpgj22/1/ –