jQuery each executes before code inside the each
Taking the code below
Why would the entire earch loop execute before the code inside it has been finished?
specifically the FadeTo block.
on line 40 to 46
- $this.Shift = function (index) {
- console.log("Shift(): Starting");
- console.log("Shift(): Clicked index " + index);
- $($this.carouItems).each(function () {
- console.log("Shift(): currentItem index " + this.index);
- var dif = 0;
- if (index < activeIndex) {
- dif = Math.abs(activeIndex - index);
- console.log("Shift(): Difference " + dif);
- if (this.index + dif > $this.carouItems.length - 1) {
- this.index = (((this.index + dif) - 1) - ($this.carouItems.length - 1));
- }
- else {
- this.index = this.index + dif;
- }
- }
- else if (index > activeIndex) {
- dif = index - activeIndex;
- console.log("Shift(): Difference " + dif);
- if (this.index - dif < 0) {
- this.index = ($this.carouItems.length - Math.abs(this.index - dif));
- }
- else {
- this.index = this.index - dif;
- }
- }
- // Rearrange all items
- var currentItem = $('#' + this.id),
- newIndex = this.index;
- console.log("Shift(): new index " + this.index);
-
- currentItem.fadeTo('slow', 0.5, function () {
- console.log("Shift(): InsideFade " + newIndex);
- $this.CalculateNewPos(newIndex);
- $this.CalculateAngle(newIndex);
- $(this).fadeTo('slow', 1.0);
- });
-
- });
- console.log("Shift(): Finished");
- }