我有一个手风琴功能,不调整窗口的顶部打开元素时,它被点击。查看移动或小屏幕大小,以了解我在说什么:http://startyourlife.com/biz-training/
下面是一个可以工作的示例:http://tympanus.net/Tutorials/FlexibleSlideToTopAccordion/
如果单击它,您将看到它滚动到该元素的顶部。下面是我目前拥有的javascript:
if (section_title.length) {
section_title.click(function () {
if ((!section.hasClass('active')) && (!running)) {
running = true;
var currentHeight, newHeight;
items.each(function () {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
}
});
if (item.length) {
item.addClass('active');
}
sections.each(function () {
if ($(this).hasClass('active')) {
currentHeight = $(this).find('.w-timeline-section-content').height();
$(this).find('.w-timeline-section-content').slideUp();
}
});
newHeight = section_content.height();
if (activeIndex < index) {
$('html').animate({
scrollTop: $('html').scrollTop() - currentHeight
});
}
section_content.slideDown(null, function () {
sections.each(function () {
if ($(this).hasClass('active')) {
$(this).removeClass('active');
}
});
section.addClass('active');
activeIndex = index;
running = false;
});
}
});
}发布于 2014-05-22 15:11:21
修正后,在最后一行“the = false”后面添加以下内容
var target = $(section);
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}https://stackoverflow.com/questions/23789459
复制相似问题