在 jQuery 中单击后滚动到向下滑动的元素
我正在寻找如何滚动到下一个元素,如下所示:
单击这些大字母,它在单击和向下滑动效果后滚动到当前元素。
这是我的尝试:(JSFiddle:http://jsfiddle.net/d272P/)
HTML< /强>
<div id="head1">Click</div>
<div id="child1">Content</div>
<br/>
<div id="head2">Click</div>
<div id="child2">Content</div>
<br/>
<div id="head3">Click</div>
<div id="child3">Content</div>
CSS
#head1{width: 400px; height: 40px; background: orange;}
#head2{width: 400px; height: 40px; background: red;}
#head3{width: 400px; height: 40px; background: purple;}
#child1{width: 300px; height: 700px; background: green; display: none;}
#child2{width: 300px; height: 700px; background: cyan; display: none;}
#child3{width: 300px; height: 700px; background: pink; display: none;}
JavaScript
$('#head1').click(function() {
$('#child1').animate({
opacity: 'toggle',
height: 'toggle'
},
{
duration: 750,
specialEasing: {
width: 'linear',
height: 'easeInOutQuad'
},
}
);
});
$('#head2').click(function() {
$('#child2').animate({
opacity: 'toggle',
height: 'toggle'
},
{
duration: 750,
specialEasing: {
width: 'linear',
height: 'easeInOutQuad'
},
}
);
});
$('#head3').click(function() {
$('#child3').animate({
opacity: 'toggle',
height: 'toggle'
},
{
duration: 750,
specialEasing: {
width: 'linear',
height: 'easeInOutQuad'
},
}
);
});
I was looking how to scroll into next element like this:
Click those big letters and it does scroll to current element after of click and slide down effect.
There is my attempt: (JSFiddle: http://jsfiddle.net/d272P/)
HTML
<div id="head1">Click</div>
<div id="child1">Content</div>
<br/>
<div id="head2">Click</div>
<div id="child2">Content</div>
<br/>
<div id="head3">Click</div>
<div id="child3">Content</div>
CSS
#head1{width: 400px; height: 40px; background: orange;}
#head2{width: 400px; height: 40px; background: red;}
#head3{width: 400px; height: 40px; background: purple;}
#child1{width: 300px; height: 700px; background: green; display: none;}
#child2{width: 300px; height: 700px; background: cyan; display: none;}
#child3{width: 300px; height: 700px; background: pink; display: none;}
JavaScript
$('#head1').click(function() {
$('#child1').animate({
opacity: 'toggle',
height: 'toggle'
},
{
duration: 750,
specialEasing: {
width: 'linear',
height: 'easeInOutQuad'
},
}
);
});
$('#head2').click(function() {
$('#child2').animate({
opacity: 'toggle',
height: 'toggle'
},
{
duration: 750,
specialEasing: {
width: 'linear',
height: 'easeInOutQuad'
},
}
);
});
$('#head3').click(function() {
$('#child3').animate({
opacity: 'toggle',
height: 'toggle'
},
{
duration: 750,
specialEasing: {
width: 'linear',
height: 'easeInOutQuad'
},
}
);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JQuery ScrollTo 应该可以解决问题
编辑
在查看示例网站后,我意识到 JQuery UI Accordian 可能是更好的选择。
JQuery ScrollTo should do the trick
Edit
After reviewing the sample site, I realise that JQuery UI accordian might be the better option.
可以通过使用 jquery Accordion
检查链接 http://jqueryui.com/demos/accordion/
this functionality can be achived by using jquery accordion
check the link http://jqueryui.com/demos/accordion/