我想创建一个侧滚动菜单,如here。我有什么:使用CSS和jQuery的侧滚动菜单
HTML:
<div class="scroll">
<p class="scroll_item" id="1"> </p>
<p class="scroll_item" id="2"> </p>
<p class="scroll_item" id="3"> </p>
<p class="scroll_item" id="4"> </p>
</div>
<div id="first"> 1 </div>
<div id="second"> 2 </div>
<div id="third"> 3 </div>
<div id="fourth"> 4 </div>
CSS:
.scroll{
position:fixed;
height:48%;
right:4px;
top:48%
}
.scroll_item{
margin-bottom:10px;
width:10px;
height:10px;
border: 3px solid #FFF;
}
.scroll_item_active{
width:10px;
height:10px;
border:3px solid #FFF;
background-color: #FFF;
margin-bottom: 10px;
}
如何这应该工作: 当你点击<p>
id为3,将滚动到与DIV ID“第三”,并且该盒子将具有scroll_item_active
类。另一方面,如果你使用浏览器的滚动条,框的类将会改变。
我需要你的帮助来编写jQuery脚本。 我所做的:
$('#1').onclick(function(.scrollTo('#first');)
$('#2').onclick(function(.scrollTo('#second');)
$('#3').onclick(function(.scrollTo('#third');)
$('#4').onclick(function(.scrollTo('#fourth');)
你的代码有什么错误? – Michael
您在'.scrollTo('#fourth');'之前缺少选择器。像'$('body,html')。scrollTo()'或'$(document)' – Spokey