我有一个非常简单的 jQuery 下拉式登录。我唯一的问题是,我不希望它在单击站点上任何位置的链接和/或刷新页面时不“重新启动”/返回,直到用户单击关闭按钮。 不确定这是否可能。
$(document).ready(function() {
// Expand Panel
$("#open").click(function(){
$("div#panel").slideDown(2000, "easeOutBounce");
});
// Expand Panel
$("#open").click(function(){
$("body").slideDown("slow");
});
// Collapse Panel
$("#close").click(function(){
$("div#panel").slideUp(2000, "easeInBack");
});
// Switch buttons from "Log In | Register" to "Close Panel" on click
$("#toggle a").click(function () {
$("#toggle a").toggle();
});
});
最佳答案
您可以在它向下滑动时创建一个 cookie,并在每次调用 $(document).ready() 时查看该 cookie 是否存在并相应地打开面板。
您可以在谷歌上搜索“如何使用 javascript 设置 cookie”或按照 Konstantin D 的建议使用 $.cookie。
在你的代码中查看我的注释以清楚地理解:
$(document).ready(function() {
// see if cookie exists. if it does do the following
// $('div#panel').show();
// if it does not, you don't have to do anything
// Expand Panel
$("#open").click(function(){
$("div#panel").slideDown(2000, "easeOutBounce");
// now that it is opened, you should set your cookie here!
});
// Expand Panel
$("#open").click(function(){
$("body").slideDown("slow");
});
// Collapse Panel
$("#close").click(function(){
$("div#panel").slideUp(2000, "easeInBack");
// once it is closed by user, remember to delete the cookie.
});
// Switch buttons from "Log In | Register" to "Close Panel" on click
$("#toggle a").click(function () {
$("#toggle a").toggle();
});
关于javascript - jQuery slidedown 点击后不隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12667749/