如何使幻灯片仅在第一次单击时向左移动并在第一次单击时拒绝向左移动?
How can I make the slide move left only on the first click and deny it from moving left on the first click?
我的幻灯片区域在单击左键时向右滚动,但是那里什么也没有,所以有没有办法锁定第一次单击,以便只有先向右滚动时才能向左滚动?还有一种方法可以在滚动到最后一个后锁定滚动条吗div?
var $slider = $("#recent-container")
$("#right-button").click(function() {
$slider.css("left", "-=932px")
});
$("#left-button").click(function() {
$slider.css("left", "+=932px")
});
/*----------Recent Projects----------*/
#recent-title {
font-size: 30px;
font-family: 'calibri light';
border-bottom: #d8d8d8 solid 1px;
margin: 0px;
padding: 10px;
box-shadow: 0 10px 10px -5px rgba(0, 0, 0, 0.3);
}
.thmbnl-name {
font-size: 20px;
font-family: 'calibri light';
text-align: center;
}
#recent {
text-align: center;
border: #d8d8d8 solid 1px;
overflow: hidden;
position: relative;
width: 950px;
height: 330px;
background-color: white;
z-index: 1;
margin-bottom: 25px;
}
#recent #recent-container {
position: absolute;
white-space: nowrap;
left: 0;
-webkit-transition: all 2s ease-in-out;
transition: all 1s ease-in-out;
z-index: -1;
padding: 10px;
}
#recent #recent-container .thmbnl-recent {
display: inline-block;
}
.thmbnl-recent {
padding: 19.5px;
}
.thmbnl-recent:hover {
background-color: #eaeaea;
transition: background-color ease 1s;
}
#right-button {
font-family: 'calibri';
font-weight: bold;
border-style: none;
width: 60px;
height: 60px;
font-size: 35px;
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
right: 0px;
top: 37.5%;
cursor: pointer;
color: #e5e5e5;
border-radius: 100%;
text-align: center;
line-height: 55px;
}
#left-button {
font-family: 'calibri';
font-weight: bold;
border-style: none;
width: 60px;
height: 60px;
font-size: 35px;
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
left: 0px;
top: 37.5%;
cursor: pointer;
color: #e5e5e5;
border-radius: 100%;
text-align: center;
line-height: 55px;
}
<div id="recent">
<h2 id="recent-title">Recent Projects</h2>
<div id="recent-container">
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
</div>
<p id="right-button">></p>
<p id="left-button">
<</p>
</div>
您可以尝试将按钮功能更改为仅在 recent-container
不在末尾时才更改 CSS。例如,对于右键:
var $slider = $("#recent-container");
$("#right-button").click(function() {
if ($slider.position().left + $slider.width() > 0) $slider.css("left", "-=932px");
});
$("#left-button").click(function() {
if ($slider.position().left < 0) $slider.css("left", "+=932px");
});
我的幻灯片区域在单击左键时向右滚动,但是那里什么也没有,所以有没有办法锁定第一次单击,以便只有先向右滚动时才能向左滚动?还有一种方法可以在滚动到最后一个后锁定滚动条吗div?
var $slider = $("#recent-container")
$("#right-button").click(function() {
$slider.css("left", "-=932px")
});
$("#left-button").click(function() {
$slider.css("left", "+=932px")
});
/*----------Recent Projects----------*/
#recent-title {
font-size: 30px;
font-family: 'calibri light';
border-bottom: #d8d8d8 solid 1px;
margin: 0px;
padding: 10px;
box-shadow: 0 10px 10px -5px rgba(0, 0, 0, 0.3);
}
.thmbnl-name {
font-size: 20px;
font-family: 'calibri light';
text-align: center;
}
#recent {
text-align: center;
border: #d8d8d8 solid 1px;
overflow: hidden;
position: relative;
width: 950px;
height: 330px;
background-color: white;
z-index: 1;
margin-bottom: 25px;
}
#recent #recent-container {
position: absolute;
white-space: nowrap;
left: 0;
-webkit-transition: all 2s ease-in-out;
transition: all 1s ease-in-out;
z-index: -1;
padding: 10px;
}
#recent #recent-container .thmbnl-recent {
display: inline-block;
}
.thmbnl-recent {
padding: 19.5px;
}
.thmbnl-recent:hover {
background-color: #eaeaea;
transition: background-color ease 1s;
}
#right-button {
font-family: 'calibri';
font-weight: bold;
border-style: none;
width: 60px;
height: 60px;
font-size: 35px;
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
right: 0px;
top: 37.5%;
cursor: pointer;
color: #e5e5e5;
border-radius: 100%;
text-align: center;
line-height: 55px;
}
#left-button {
font-family: 'calibri';
font-weight: bold;
border-style: none;
width: 60px;
height: 60px;
font-size: 35px;
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
left: 0px;
top: 37.5%;
cursor: pointer;
color: #e5e5e5;
border-radius: 100%;
text-align: center;
line-height: 55px;
}
<div id="recent">
<h2 id="recent-title">Recent Projects</h2>
<div id="recent-container">
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
<div class="thmbnl-recent">
<img src="http://placehold.it/190x190">
<h1 class="thmbnl-name">Sample</h1>
</div>
</div>
<p id="right-button">></p>
<p id="left-button">
<</p>
</div>
您可以尝试将按钮功能更改为仅在 recent-container
不在末尾时才更改 CSS。例如,对于右键:
var $slider = $("#recent-container");
$("#right-button").click(function() {
if ($slider.position().left + $slider.width() > 0) $slider.css("left", "-=932px");
});
$("#left-button").click(function() {
if ($slider.position().left < 0) $slider.css("left", "+=932px");
});