下面的代码是我正在运行的用来创建手风琴风格的sidemenu的JS。类别类嵌套在组类中,而组类嵌套在节类中。如何更改此JS,使其在幻灯片向上或向下滑动事件后转到href?我需要html中的href。
(function ($) {
$(document).ready(function () {
var activeElement = $('#cssmenu').find('.active');
activeElement.parentsUntil(".section").show();
$('.section > a').click(function () {
$('#cssmenu li').removeClass('active');
$(this).closest('li').addClass('active');
var checkElement = $(this).next();
if ((checkElement.is('.group-list')) && (checkElement.is(':visible'))) {
$(this).closest('li').removeClass('active');
checkElement.slideUp('normal');
}
if ((checkElement.is('.group-list')) && (!checkElement.is(':visible'))) {
$('.group-list:visible').slideUp('normal');
$('.category-list:visible').slideUp('normal');
checkElement.slideDown('normal');
}
if ($(this).closest('li').find('ul').children().length == 0) {
return true;
} else {
return false;
}
});
$('.group > a').click(function (e) {
$('#cssmenu li').removeClass('active');
$(this).closest('li').addClass('active');
var checkElement = $(this).next();
if ((checkElement.is('.category-list')) && (checkElement.is(':visible'))) {
$(this).closest('li').removeClass('active');
checkElement.slideUp('normal');
}
if ((checkElement.is('.category-list')) && (!checkElement.is(':visible'))) {
$('.category-list:visible').slideUp('normal');
checkElement.slideDown('normal');
}
if ($(this).closest('li').find('ul').children().length == 0) {
return true;
} else {
return false;
}
window.location.href = $(this).attr('href');
});
$('.category > a').click(function () {
$('#cssmenu li').removeClass('active');
$(this).closest('li').addClass('active');
var checkElement = $(this).next();
if ((checkElement.is('.category-list')) && (checkElement.is(':visible'))) {
$(this).closest('li').removeClass('active');
}
if ($(this).closest('li').find('ul').children().length == 0) {
return true;
} else {
return false;
}
window.location.href = $(this).attr('href');
});
});
})(jQuery);发布于 2015-07-06 20:05:37
jQuery的slideUp和slideDown方法接受回调:
http://api.jquery.com/slideup/
例如:
$('.group > a').click(function() {
var checkElement = $(this).next();
var href = $(this).attr('href');
checkElement.slideUp('normal', function() {
window.location.href = href;
});
});发布于 2015-07-06 20:05:03
jQuery的slideUp() (和slideDown)事件接受一个回调函数,该回调函数在动画完成后执行。然后您可以只使用scrollIntoView()或任何您想要的东西。
https://stackoverflow.com/questions/31254535
复制相似问题