Thursday, 15 January 2015

javascript - Animate jQuery toggle only once per call -



javascript - Animate jQuery toggle only once per call -

i have pretty complex scheme few ajax calls render different templates other templates in php.

one of these templates edit form entity. form rendered hidden website until button clicked, fire jquery toggle() switch out part of site edit form.

this works fine until user using jquery ui slider on site.

what happens if user navigates within slider parts of site reloaded ajax.

when button toggle() clicked animation goes of slider used (so if slider used 4 times toggle animate switch out 2 elements 4 times).

i debugged through , couldn't find mistake, can't provide jsfiddle rebuild situation nor can give access site. click function fired once, can't explain why happening.

to mention have 3 buttons trigger event:

#poi_edit_ajax shown when slider used in template rendered per ajax.

#poi_edit_first shown first access site , nil has been reloaded per ajax.

#poi_edit_last shown user can come edit view

the javascript following:

$("#poi_edit_ajax").click(function(){ $(".toggle_edit").toggle('slow'); }); $("#poi_edit_first").click(function(){ $(".toggle_edit").toggle('slow'); }); $("#poi_edit_last").click(function(){ $(".toggle_edit").toggle('slow'); });

i don't think can give me solution information, that's can provide now, question if possible tell toggle() function jquery run animation 1 time per click.

i don't think jquery one() can used this, because click event used 1 time per pagevisit.

edit

according comment, tried out if multiple event handlers registered within ajax calls, true.

the code prepare simple:

$("#comment_first").unbind("click").click(function(){ $('.toggle_information').toggle('slow'); }); $("#comment_last").unbind("click").click(function(){ $('.toggle_information').toggle('slow'); }); $("#comment_ajax").unbind("click").click(function(){ $('.toggle_information').toggle('slow'); });

i need unbind lister before bind again, else they're gonna stuck , multiple listeners react click event!

you binding click event multiple times (by loading javascript through ajax calls). create sure bind click handler (which triggers toggle()) once.

take @ answer: http://stackoverflow.com/a/969011

a (slightly modified) quote answer, quick reference:

function alertevent() { alert("test"); }

$(".ajax").bind("click", alertevent);

//when want ensure won't happen twice...

$(".ajax").unbind("click", alertevent);

$(".ajax").bind("click", alertevent);

this method remove event specify

javascript jquery html ajax

No comments:

Post a Comment