gpt4 book ai didi

javascript - div slider 不工作

转载 作者:行者123 更新时间:2023-11-28 13:27:24 26 4
gpt4 key购买 nike

我在 StackOverflow 中的一些帖子的帮助下创建了一个 div slider ,但由于某种原因它不起作用。显示 Jquery 有一些错误,我没有看到。我需要第二双眼睛

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Previous Next</title>
<style type="text/css">
.table-container {
width:456px; /* Total width of visible columns + border widths */
height:300px;
border:solid 1px #000;
background-color:#eee;
overflow:hidden;
}

.sliding-window {
width:760px; /* Total width of all columns in sliding-window + border widths */
height:300px;
overflow:hidden;
}

.sliding-window div {
float:left;
width:150px;
height:300px;
background-color:#aaa;
border:solid 1px #999;
}

</style>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {

$('#next-column').click(function(event) {
event.preventDefault();
$('.table-container').animate({scrollLeft:'+=152'}, 'slow');
});

$('#previous-column').click(function(event) {
event.preventDefault();
$('.table-container').animate({scrollLeft:'-=152'}, 'slow');
});

});​
</script>

</head>

<body>

<a id="previous-column" href="#">Previous</a>
<a id="next-column" href="#">Next</a>
<div class="table-container">
<div class="sliding-window">
<div id="col-1">
<p>This is the content of the first column in the sliding table</p>
</div>
<div id="col-2">
<p>This is the content of the second column in the sliding table</p>
</div>
<div id="col-3">
<p>This is the content of the third column in the sliding table</p>
</div>
<div id="col-4">
<p>This is the content of the fourth column in the sliding table</p>
</div>
<div id="col-5">
<p>This is the content of the fifth column in the sliding table</p>
</div>
</div>
</div>

</body>

</html>

最佳答案

您可以尝试一些方法来使它正常工作。

确保您的脚本被拉入页面,一种检查方法是使用 Chrome 调试器中的“来源”选项卡并在 html head 部分中搜索其他文件

确保在包含 jQuery 之后包含 datatale 脚本,因为它肯定依赖于它。

检查 jQuery 是否被正确包含并且只包含一次。

注意 jQuery 冲突。还有一些其他库覆盖了 $,因此您的代码无法正常工作,因为 $ 不再是 jQuery 的别名。您可以使用 jQuery.noConflict() 来避免与页面上使用相同变量 $ 的其他库发生冲突。

关于javascript - div slider 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14003433/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com