• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Wir haben den Frühjahrsputz beendet, Ihr auch? Welches Foto zu dem Thema hat Euch dann am Besten gefallen? Hier geht es lang zur Abstimmung --> Klick

[JS]: var m=t[y] - funktioniert das?

C64

Kaiser Alexander
Registriert
12.04.06
Beiträge
3.957
Hallo zusammen,

mal wieder ich :)

Diesmal versuche ich mir ein Skript anzupassen, um mehrerer solcher Bildergalerien auf einer Seite haben zu können.

Die wichtigste Passagen:
Hier setze ich in der each-Schleife am Ende immer t[1]=z, so dass im Array t an der Stelle 1 am Ende der letzte Wert von z steht. Das gleiche mache ich für die anderen Stellen (testhalber nur bis 2)

Beim Klick möchte ich unter anderem y=1 (bzw. der Nummer der Klasse testx) setzen.
$(".test1").click(function() {
var y=1;
$(".test1").addClass("pictures");
return swapFirstLast(true); //swap first image to last position
});

In der Funktion die auf einen Klick hin ausgeführt wird setze ich:
Wenn ich hier die 1 oder 2 für y manuell einsetze, dann klappt es jeweils für die Bilder mit Klasse test1 bzw. test2. Aber es will nicht funktionieren, wenn ich t[y] schreibe.

Wo liegt hier mein Denkfehler?


Der komplette Code von mir:
$(document).ready(function() { //perform actions when DOM is ready
t = new Array();
$('.test1').addClass('pictures');
var z = 0; //for setting the initial z-index's
var inAnimation = false; //flag for testing if we are in a animation
$('.pictures img').each(function() { //set the initial z-index's
z++; //at the end we have the highest z-index value stored in the z variable
$(this).css('z-index', z); //apply increased z-index to <img>
t[1]=z;
});
$('.pictures').removeClass('pictures');
$('.test2').addClass('pictures');
var z = 0; //for setting the initial z-index's
$('.pictures img').each(function() { //set the initial z-index's
z++; //at the end we have the highest z-index value stored in the z variable
$(this).css('z-index', z); //apply increased z-index to <img>
t[2]=z;
});
$('.pictures').removeClass('pictures');

function swapFirstLast(isFirst) {
if(inAnimation) return false; //if already swapping pictures just return
else inAnimation = true; //set the flag that we process a image
var processZindex, direction, newZindex, inDeCrease; //change for previous or next image
var m = t[y];
if(isFirst) { processZindex = m; direction = '-'; newZindex = 1; inDeCrease = 1; } //set variables for "next" action
else { processZindex = 1; direction = ''; newZindex = m; inDeCrease = -1; } //set variables for "previous" action

$('.pictures img').each(function() { //process each image
if($(this).css('z-index') == processZindex) { //if its the image we need to process
$(this).animate({ 'top' : direction + $(this).height() + 'px' }, '100', function() { //animate the img above/under the gallery (assuming all pictures are equal height)
$(this).css('z-index', newZindex) //set new z-index
.animate({ 'top' : '0' }, '100', function() { //animate the image back to its original position
inAnimation = false; //reset the flag
});
});
} else { //not the image we need to process, only in/de-crease z-index
$(this).animate({ 'top' : '0' }, '100', function() { //make sure to wait swapping the z-index when image is above/under the gallery
$(this).css('z-index', parseInt($(this).css('z-index')) + inDeCrease); //in/de-crease the z-index by one
});
}
});
$('.pictures').removeClass('pictures');
return false; //don't follow the clicked link
}
$(".test1").click(function() {
var y=1;
$(".test1").addClass("pictures");
return swapFirstLast(true); //swap first image to last position
});

$(".test2").click(function() {
var y=2;
$(".test2").addClass("pictures");
return swapFirstLast(true); //swap first image to last position
});

$('.prev a').click(function() {
return swapFirstLast(false); //swap last image to first position
});
});
 

C64

Kaiser Alexander
Registriert
12.04.06
Beiträge
3.957
Sorry, ich hab schon wieder Tomaten auf den Augen gehabt!!! 3 Stunden hab ich jetzt gebastelt und dann gemerkt, das ich die Variable lokal und nicht global definiert hab!!! :eek:
Sorry, für meine Tomatenaugen! ;)

Jetzt klappt alles soweit erst mal... :)