jquery slideToggle call once

邮差的信 提交于 2020-01-05 03:43:27

问题


That just could be very simple, but it's about 2AM and getting quite sleepy :)

I have short script which "slideToggle" div from being non-displayed.

$('#cmnt_add').click(function () { $('.dark_div_add').slideToggle(1100); });

Is there a chance to make it workout once, so if non-displayed DIV is opened, clicking same link won't do a thing?

Thank you in advance!


回答1:


Use .one():

$('#cmnt_add').one("click", function () { $('.dark_div_add').slideToggle(1100); });

From jQuery's documentation:

Attach a handler to an event for the elements. The handler is executed at most once per element.

Also, if you know it'll be hidden initially, using .slideDown() instead of .slideToggle() may be a good idea...




回答2:


use slideDown in stead of slideToggle




回答3:


$('#cmnt_add').click(function () { $('.dark_div_add').slideDown(1100); });


来源:https://stackoverflow.com/questions/15799094/jquery-slidetoggle-call-once

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