jQuery 切换滑出面板
我正在使用滑出面板,默认设置为“显示:无”。如果单击触发器,它将将该类切换为“活动”。这使得触发器显示来自精灵位置的红色 x(表示关闭)。
$(document).ready(function(){
$(".info-panel-left-trigger").click(function(){
$("#info-panel-left").toggle(400);//switching between display and display:none
$(this).toggleClass("active");
return false;
});
}); 这就是我所拥有的,但现在来了我想要的,也许你们中的一个人知道如何实现这一目标。
我想创建一个选项,让面板在默认情况下显示或在默认情况下隐藏,然后切换应该采取相应的行为。这意味着,如果我选择默认显示面板,则应将切换设置为“活动”,以便显示 x 精灵位置。如果我选择默认隐藏面板,则应将切换设置为“未激活”,以便显示 + 精灵位置。
我希望我已经说得足够清楚了。 非常感谢帮助。
编辑你们是对的。需要更多解释。我只是想让它尽可能短,但这里还有更多...
我正在创建一个网站模板,模板的购买者应该能够包含这些面板以供参考。默认情况下,它应该设置显示面板并将触发器类别设置为“活动”。这将显示我的小 x 关闭。
但是,如果模板的购买者将额外的类“隐藏”添加到面板标记中,则面板应默认隐藏,并且触发器不应设置为活动状态,因为在这种情况下我的触发器会显示用于打开此面板的小+。现在明白我的想法了吗?
I am using slide out panel that on default is set to display:none. If the trigger is clicked it will toggle the class to "active". That makes the trigger show a red x (for close) that comes from a sprite position.
$(document).ready(function(){
$(".info-panel-left-trigger").click(function(){
$("#info-panel-left").toggle(400);//switching between display and display:none
$(this).toggleClass("active");
return false;
});
});
So this is what I have but now comes what I want and maybe one of you got a clou how to achieve this.
I would like to create the option to have the panel either shown on default or hidden on default and the toggle should behave accordingly. This would mean that if I have chosen to show the panel on default that the toggle should be set to "active" in order to show the x sprite position. If I have chosen to hide the panel on default the toggle should be set to "not active" in order to show the + sprite position.
I hope I have made myself clear enough. HELP is appreciated very much.
EDIT You guys are right. Some more explanation is needed. I just wanted it to make as short as possible but here is some more...
I am creating a website template and the buyer of the template should be able to include those panels for information purposes. On default it should set up showing the panel and have set the trigger class to "active". This would show my little x for close.
But if the buyer of the template add the extra class "hide" to the panel markup the panel should be hidden on default and the trigger should not be set to active because in that case my trigger would show the little + for open this panel. Got my idea now?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将此默认值存储在何处(以及持久性如何)?仅在客户端进行该会话,还是在服务器端?服务器端对我来说似乎最合乎逻辑。如果是这样,当用户选择显示面板时,向 info-panel-left 的 html 添加一个类。假设我们添加了
一些 javascript,以便它读取
(当然,您也可以使用“active”类)
编辑:好的;如果我们只坚持 JS 部分,我认为这不会改变方法太多,不是吗?只要反转它:
然后
Where (and how persistent) do you store this default? Just on the client for that session, or server-side? Server-side would seem most logical to me.. if so, when the user has chosen to show the panel, add a class to the info-panel-left's html. Assuming we then have
Add a bit of javascript so it reads
(you could just use the 'active' class as well of course)
EDIT: okay; if we just stick to the JS part, I don't think that changes the approach much, does it? Just reverse it:
then