首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在jquery事件之后转到href。

问在jquery事件之后转到href。
EN

Stack Overflow用户
提问于 2015-07-06 19:56:30
回答 2查看 105关注 0票数 0

下面的代码是我正在运行的用来创建手风琴风格的sidemenu的JS。类别类嵌套在组类中,而组类嵌套在节类中。如何更改此JS,使其在幻灯片向上或向下滑动事件后转到href?我需要html中的href。

代码语言:javascript
复制
(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);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-07-06 20:05:37

jQuery的slideUp和slideDown方法接受回调:

http://api.jquery.com/slideup/

例如:

代码语言:javascript
复制
$('.group > a').click(function() {
    var checkElement = $(this).next();
    var href = $(this).attr('href');
    checkElement.slideUp('normal', function() {
        window.location.href = href;
    });
});
票数 2
EN

Stack Overflow用户

发布于 2015-07-06 20:05:03

jQuery的slideUp() (和slideDown)事件接受一个回调函数,该回调函数在动画完成后执行。然后您可以只使用scrollIntoView()或任何您想要的东西。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31254535

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档