我有以下小提琴:http://jsfiddle.net/k7csj8Lf/
$(document).ready(function () {
function close_accordion_section() {
$('.accordion .accordion-section-title').removeClass('active');
$('.accordion .accordion-section-content').slideUp(300).removeClass('open');
}
$('.accordion-section-title').click(function (e) {
// Grab current anchor value
var currentAttrValue = $(this).attr('href');
if ($(e.target).is('.active')) {
close_accordion_section();
} else {
close_accordion_section();
// Add active class to section title
$(this).addClass('active');
// Open up the hidden content panel
$('.accordion ' + currentAttrValue).slideDown(300).addClass('open').animate({
scrollTop: -50
});
}
e.preventDefault();
});
$(".accordion .accordion-section-title:eq(0)").trigger('click');
$('.accordion-section-title').bind('click', function () {
var self = this;
setTimeout(function () {
theOffset = $(self).offset();
$('body,html').animate({
scrollTop: theOffset.top - 50
});
}, 300); // ensure the collapse animation is done
});
});`
滚动到顶部功能似乎在小提琴中正常工作,但在我的浏览器中使用相同的代码在我的机器上无法正常工作。
非常感谢任何帮助。