unwohltaeter
Mitglied
Wie bekomme ich es hin, dass in einem Container genau das Bild mit dem größten Z-Index ausgewählt wird und eine Klasse (z.B. class="top") angehängt bekommt?
Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature currently requires accessing the site using the built-in Safari browser.
in einem Container
//Der container
var con = document.getElementById('container');
das Bild
//Alle Bilder in dem container
var images = con.getElementsByTagName('img');
mit dem größten Z-Index
//Maximum suchen
var maxImg = null, maxZ = -1;
for(var i = 0; i < images.length; i++) {
var z = images[i].style.zIndex | 0;
if(z > maxZ) {
z = maxZ;
maxImg = images[i];
}
}
eine Klasse (z.B. class="top") angehängt bekommt
//Klasse anhängen
maxImg.className += ' top';
Was wäre, wenn diese Bilder nochmal in einem a-Tag eingeschlossen wären?
Zum Beispiel:
$('.cloudcarousel').filter(function() {
return this.style.zIndex == 100;
});
$('.cloudcarousel').filter(function() {
return this.style.zIndex == 100;
});
$(document).ready(function(){});
Kann es sein, dass es nicht funktioniert, weil nicht nur Z-Index im Style-Attribut steht?
var carousel = $("#carousel1").CloudCarousel({
xPos: 128,
yPos: 32,
buttonLeft: $("#left-but"),
buttonRight: $("#right-but"),
altBox: $("#alt-text"),
titleBox: $("#title-text")
});
var stop = carousel.data('cloudcarousel').stop;
carousel.data('cloudcarousel').stop = function() {
stop.call(this);
};
carousel.data('cloudcarousel').stop = function() {
stop.call(this);
//Unser eigener Code!
$('.cloudcarousel').removeClass('top').filter(function() {
return this.style.zIndex == 100;
}).addClass('top');
};
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Carousel</title>
<style type="text/css">
.top {border:1px solid red;}
</style>
</head>
<body>
<div>
<div id = "carousel1" style="width:256px; height:128px;background:#000;overflow:scroll;">
<!-- All images with class of "cloudcarousel" will be turned into carousel items -->
<!-- You can place links around these images -->
<img class="cloudcarousel" src="flag1.png" alt="Flag 1 Description" title="Flag 1 Title" />
<img class="cloudcarousel" src="flag2.png" alt="Flag 2 Description" title="Flag 2 Title" />
<img class="cloudcarousel" src="flag3.png" alt="Flag 3 Description" title="Flag 3 Title" />
<img class="cloudcarousel" src="flag4.png" alt="Flag 4 Description" title="Flag 4 Title" />
<img class="cloudcarousel" src="flag5.png" alt="Flag 5 Description" title="Flag 5 Title" />
<img class="cloudcarousel" src="flag6.png" alt="Flag 6 Description" title="Flag 6 Title" />
</div>
<!-- Define left and right buttons. -->
<input id="left-but" type="button" value="Left" />
<input id="right-but" type="button" value="Right" />
<!-- Define elements to accept the alt and title text from the images. -->
<p id="title-text"></p>
<p id="alt-text"></p>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js"></script>
<script type="text/javascript" src="cloud-carousel.1.0.5.js"></script>
<script type="text/javascript">
/* <![CDATA[ */
$(function() {
var carousel = $("#carousel1").CloudCarousel({
xPos: 128,
yPos: 32,
buttonLeft: $("#left-but"),
buttonRight: $("#right-but"),
altBox: $("#alt-text"),
titleBox: $("#title-text")
});
var stop = carousel.data('cloudcarousel').stop;
carousel.data('cloudcarousel').stop = function() {
stop.call(this);
$('.cloudcarousel').removeClass('top').filter(function() {
return this.style.zIndex == 100;
}).addClass('top');
};
});
/* ]]> */
</script>
</body>
</html>