Question:
I have this code:
<script>
$(function(){
$(".flipster").flipster({style: 'carousel', enableTouch: true, start: 0,
onItemSwitch: function(){
var nomeAlbum = $(this).attr("data-title");
console.log(nomeAlbum);
}
});
});
</script>
The onItemSwitch()
function allows me to do anything when the image is switched.
The problem is that I'm trying to take the data-titulo
of each of the images, and place it below the photo in the album.
HTML
<ul>
<li>
<img src="img/californication.jpg" data-title="Californication" class="imgCarousel"/>
<p class="mostra-titulo"></p>
</li>
<li>
<img src="img/greatest-hits.jpg" data-title="Greatest Hits" class="imgCarousel" />
<p class="mostra-titulo"></p>
</li>
<li>
<img src="img/stadium-arcadium.jpg" data-title="Stadium Arcadium" class="imgCarousel" />
<p class="mostra-titulo"></p>
</li>
<li>
<img src="img/the-uplift-mofo-party-plan.jpg" data-title="The Upflit Mofo Party Plan" class="imgCarousel"/>
<p class="mostra-titulo"></p>
</li>
</ul>
Here's the plugin repository , in case it helps.
Answer:
Try it like this:
// iterar todos os li
$('li').each(function() {
// fazer cache do objecto para evitar funções a mais a correr
// como o @Zuul referiu nos comentários
var $this = $(this);
// dentro de cada li, procurar o elemento img e
// capturar o titulo unsando o método data() do jQuery
var titulo = $this.find('img').data('title');
// procurar elementos com a classe 'mostra-titulo' e inserir o titulo no seu HTML
$this.find('.mostra-titulo').html(titulo);
});