Buona Sera
Ho il seguente codice jQuery:
che dovrebbe switchare tra tre form nella stessa pagina, grazie adcodice:$(function (){ //the form wrapper (includes all forms) var $form_wrapper = $('#form_wrap'), //the current form is the one with class active $currentForm = $form_wrapper.children('form.active'), //the change form links $linkform = $form_wrapper.change(function(){ $(this).find(":selected").val()}); //$('#form_wrap').find("option:selected").val(); $form_wrapper.children('form').each(function(i){ var $theForm = $(this); if(!$theForm.hasClass('active')) $theForm.hide(); $theForm.data({ width : $theForm.width(), height: $theForm.height() }); }); setWrapperWidth(); $linkform.on('change',function(e){ var $link = $(":selected",this); var target = $link.attr('value'); $currentForm.customFadeOut(400,function(){ $currentForm.removeClass('active'); $currentForm= $form_wrapper.children('form.'+target); $form_wrapper.stop() .animate({ width : $currentForm.data('width') + 'px', height : $currentForm.data('height') + 'px' },500,function(){ $currentForm.addClass('active'); $currentForm.customFadeIn(400); }); }); e.preventDefault(); }); function setWrapperWidth(){ $form_wrapper.css({ width : $currentForm.data('width') + 'px', height : $currentForm.data('height') + 'px' }); } }); });
che è inserito in ognuno dei form.codice:<select class="linkform" id="multi3"/> <option > Seleziona... </option> <option name="info" value="info"> Info </option> <option name="assistenza" value="assistenza">Assistenza</option> <option name="prodotti" value="prodotti"> Prodotti </option> </select>
Il problema è che la prima volta l'animazione cambia il form, ma da li in poi
esegue il fadeIn e il fadeOut sempre sullo stesso form, senza cambiare più la classe ('active').
A mio avviso il problema sta nelle righe
ecodice:$linkform = $form_wrapper.change(function(){ $(this).find(":selected").val()});
ma non saprei come scriverlo altrimenti con i select.codice:var $link = $(":selected",this); var target = $link.attr('value');
Ogni suggerimento e soluzione è ben accettata.
Ringrazio in anticipo


Rispondi quotando