问题
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