scrollTo Jquery 不起作用,我错过了什么?
我已经使用过这个插件很多次了,但我要么非常愚蠢,要么脑子里放屁,因为我就是无法让它工作。我有 3 个 div,我想在另一个 div(容器 div)中滚动。
这是“不起作用的设置”的链接,这是代码...
$(document).ready(function() {
$("#sc").click(function() {
$('#main_hold').scrollTo('#m1');
});
$("#ac").click(function() {
$('#main_hold').scrollTo('#m2');
});
$("#cc").click(function() {
$('#main_hold').scrollTo('#m3');
});
});
和 HTML *请注意,空格用于没有文本的间距...
<body>
<div id="container">
<header>
<div id = "navigation">
<ul>
<li><a href="javascript:;" id = "sc">Services</a></li>
<li><a href="javascript:;" id = "ac">About</a></li>
<li><a href="javascript:;" id = "cc">Contact</a></li>
</ul>
</div>
</header>
<div id = "main_hold" role="main">
<div id = "m1" class = "mhold">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id = "m2" class = "mhold">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id = "m3" class = "mhold">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div style="clear:both"></div>
</div>
<footer>
</footer>
</div>
</body>
I've used this plug in numerous times and I'm either being very dumb or having a brain fart because I just can't get it to work. I have 3 div's that I want to scroll within another div(a container div).
here's a link of the "non functioning setup" and heres the code...
$(document).ready(function() {
$("#sc").click(function() {
$('#main_hold').scrollTo('#m1');
});
$("#ac").click(function() {
$('#main_hold').scrollTo('#m2');
});
$("#cc").click(function() {
$('#main_hold').scrollTo('#m3');
});
});
and the HTML
*note the blank spaces are there for spacing without text...
<body>
<div id="container">
<header>
<div id = "navigation">
<ul>
<li><a href="javascript:;" id = "sc">Services</a></li>
<li><a href="javascript:;" id = "ac">About</a></li>
<li><a href="javascript:;" id = "cc">Contact</a></li>
</ul>
</div>
</header>
<div id = "main_hold" role="main">
<div id = "m1" class = "mhold">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id = "m2" class = "mhold">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div id = "m3" class = "mhold">
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
<div style="clear:both"></div>
</div>
<footer>
</footer>
</div>
</body>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否已将 CSS 样式应用到您的
main_hold
div 并使用规则overflow:scroll;
?如果没有,您可能想滚动窗口:看看这个 jsfiddle: http://jsfiddle.net/Czkan /
Do you have a CSS style applied to your
main_hold
div with the ruleoverflow: scroll;
? If not, you may want to scroll the window instead:Take a look at this jsfiddle: http://jsfiddle.net/Czkan/