Quantcast
Channel: Forum Pasja Informatyki - Najnowsze pytania bez odpowiedzi
Viewing all articles
Browse latest Browse all 21942

dziwne zachowanie danych wewnątrz pętli $.each

$
0
0

piszę plugin do jquery. do tej pory wygląda to tak:

$.fn.jCounter = function(jsSettings) {

		var mergedSettings = $.extend(jCGlobalSettings, jsSettings);

		return this.each(function() {

			this.element = $(this);
			this.settings = mergedSettings;

            //pobiera dane z data-atrybutów elementu
			for (var key in this.settings) { 
				if (this.element.data( key.toLowerCase() ) != undefined) {
					this.settings[key] = this.element.data( key.toLowerCase() );
				}
			}

			console.log(this.settings);

            //nieistotne w tym kontekście
			if (typeof(this.settings.animation) !== "function") {
				this.settings.animation = jCAnimations[this.settings.animation];

				if (this.settings.animation !== "function") {
					this.settings.animation = jCAnimations['basic'];
				}
			}

			if (this.settings.digitsOnRight < 0) {
				this.settings.digitsOnRight = 0;
			}

			this.steps = Math.ceil(this.settings.updatesPerSec * this.settings.duration / 1000);
			this.stepCounter = 0;

			
            //wygenerowanie kolejnej wartości licznika na podstawie danych z this
			jCUpdateCounter(this);

			if (typeof(this.settings.onStart) === "function") {
				this.settings.onStart(this.element);
			}

			this.intervalId = setInterval(function(counter) {
				jCUpdateCounter(counter);

				if (counter.stepCounter > counter.steps) {
					clearInterval(counter.intervalId);

					if (typeof(counter.settings.onEnd) === "function") {
						counter.settings.onEnd(counter.element);
					}
				}
			}, this.settings.duration / this.steps, this); //przekazanie this do setInterval jako counter
		});
	};

problemem jest to że przy drugiej iteracji pętli $.each nadpisywane jest this.settings pierwszego elementu. dlatego jeżeli plugin odpalanay jest na jednym elemencie jquery wszystko wygląda ok. w innych wypadakach dane się dziwnie mieszają. czy to problem z $.each? może przekazywanie this do setInterval powoduje takie błędy?


Viewing all articles
Browse latest Browse all 21942

Trending Articles


AutoMapa 6.27.0 ( 2301 ) Polska / Europe Finał ( PC_WinCE ) Cracked


Sprawdź z którą postacią z anime dzielisz urodziny


H. H. Schild - MRI Zrozumieć Rezonans Magnetyczny [PDF] [DJVU] [PL]


Alawar Keygen POLECAM


Kombajn ziemniaczany GRIMME HLS 750


POTANIACZ


Antena kierunkowa 2 el. Delta 7 pasm wg. SP3PL


1


Renault Laguna III - kontrolki (P) oraz /check handbrake


C4 Picasso 2011 - błąd U1218