• Das Erstellen neuer Accounts wurde ausgesetzt. Bei berechtigtem Interesse bitte Kontaktaufnahme über die üblichen Wege. Beste Grüße der Admin

[FRAGE] [jQuery] Animation läuft nach Mehrfachklicks falsch

DaNeubi

New member
Hallo leute,

ich fange gerade an Javascript zu lernen und bin fleißig am scripten.

Jetz habe ich mit meinem ersten Script schon ein Problem....
Die Animation Funktioniert anfangs Problemlos, doch wenn man öfters auf die Menüpunkte Klickt wiederholt sich das ganze....

Hier das Script:

Code:
(document).ready(function() {
	var a = 0;

	$("#home").click(function() {
		var a = 1;
		$("#content1").animate({opacity:"0", filter:"alpha(opacity=0)"}, 300, function() {
			$("#content1").load("index1.html", function() {
				$("#content1").animate({opacity:"0", filter:"alpha(opacity=0)", marginLeft:"100", paddingBottom:"0"}, 500);
				$("#content1").animate({opacity:"1", filter:"alpha(opacity=100)", marginLeft:"0", paddingBottom:"0"}, 500);
				$("#content1").stop(animate);
				$("#content1").end();
			});
		});
	});
	
		$("#kont").click(function() {
			var a = 2;
		$("#content1").animate({opacity:"0", filter:"alpha(opacity=0)"}, 300, function() {
			$("#content1").load("kontakt.html", function() {
				$("#content1").animate({opacity:"0", filter:"alpha(opacity=0)", marginLeft:"100", paddingBottom:"0"}, 500);
				$("#content1").animate({opacity:"1", filter:"alpha(opacity=100)", marginLeft:"0", paddingBottom:"0"}, 500);
				$("#content1").stop(animate);
				$("#content1").end();
			});
		});
	});
	
	
		$("#imp").click(function() {
			var a = 3;
		$("#content1").animate({opacity:"0", filter:"alpha(opacity=0)"}, 300, function() {
			$("#content1").load("imptessum.html", function() {
				$("#content1").animate({opacity:"0", filter:"alpha(opacity=0)", marginLeft:"100", paddingBottom:"0"}, 500);
				$("#content1").animate({opacity:"1", filter:"alpha(opacity=100)", marginLeft:"0", paddingBottom:"0"}, 500);
				$("#content1").stop(animate);
				$("#content1").end();
			});
		});
	});
			
		if (a = 3) {
		$("#content1").close();
		$("#content1").open();
	};
	
});


Hier der Link: A-Neubauer.de | Ihr Sachverständiger

Wenn man öfter als 1 oder 2 mal auf das selbe Klickt hängt das ganze.
Weiß jemand woran das liegt, bzw was ich hier falsch mache ?

Danke im Vorraus
 
Zuletzt bearbeitet von einem Moderator:
Neubi, "bräuchte Hilfe" ist kein wirklich vielsagender Titel. Das trifft hier auf jeden Thread zu :)
Hab das mal geändert.
 
Heyho,

ja, es fehlt der einfache .stop() vor einem .animate() - dann hast es schon im Griff.

Kleiner Tipp noch, da Du sehr häufig ins DOM greifst:
Code:
var _dom = $("#content1");
_dom.stop();
_dom.animate(...);
_dom.animate(...);

Grüße
 
Ich würde ja noch die Queue ausschalten (queue Wert im options Parameter), da man sonst bei mehrmaligen Klicken lauter gleiche Animationen hintereinander sieht.
 
Zurück
Oben