我使用 JQuery 编写了一个自定义滑块来显示图像的缩略图。我有一个滑块在其中移动的外部 div。但是当幻灯片结束时,我不想进一步滑动(左右滑动)。我怎样才能做到这一点?
这是我的代码 - 您可以将其保存为 html 并运行它 -
<html>
<head>
<title>Content Slider</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
});
function left() {
$('#inner').animate({
'marginLeft': "-=200px"
}, 1000, function () {
});
}
function right() {
if ($('#inner').css('marginLeft') != "0px" && $('#inner').css('marginLeft') != "auto") {
$('#inner').animate({
'marginLeft': "+=200px"
}, 1000, function () {
});
}
}
</script>
</head>
<body>
<div style="width: 800px; height: 200px; border: 3px solid #DADADA; overflow: hidden;
padding: 5px;">
<div id="inner" style="height: 190px; overflow: hidden;">
<table cellpadding="0" cellspacing="5" style="width: 100%; height: 190px;">
<tr>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
<td valign="middle" align="center">
<div style="width: 200px; height: 100px; background-color: #DADADA">
</div>
</td>
</tr>
</table>
</div>
</div>
<table style="width: 800px">
<tr>
<td align="left">
<a href="Javascript:left();"><<</a>
</td>
<td align="right">
<a href="Javascript:right();">>></a>
</td>
</tr>
</table>
</body>
</html>
有任何想法吗?