How to open a specific slider on the next page with jQuery

久未见 提交于 2019-12-25 02:34:29

问题


I want to open a slider on the next page when pressing a button but there is more than one button. Further, when I press one of the buttons then I want the info slider to open the one I clicked on the previous page.

here is the code:

$(document).ready(function () {
    $("h3.open-close").click(function () {
        if ($(this).is(".current")) {
            $(this).removeClass("current");
            $(this).next(".desc").slideUp(400);
        } else {
            $(".desc").slideUp(4.00);
            $("h3.open-close").removeClass("current");

            $(this).addClass("current");
            $(this).next(".desc").slideDown(400);
            $(function () {
                if (window.location.hash) {
                    $(window.location.hash).show();
                }
            });
        }
    });
});

回答1:


Your updated code:

$(document).ready(function () {
    if (window.location.hash) {
       $(window.location.hash).show(); // <--if true then do this.
    }
    $("h3.open-close").click(function () {
        if ($(this).is(".current")) {
            $(this).removeClass("current");
            $(this).next(".desc").slideUp(400);
        } else {
            $(".desc").slideUp(4.00);
            $("h3.open-close").removeClass("current");

            $(this).addClass("current");
            $(this).next(".desc").slideDown(400);
        }
    });
});

You have to check for the hash at dom ready.



来源:https://stackoverflow.com/questions/22346848/how-to-open-a-specific-slider-on-the-next-page-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!