0
I’m trying to change the image using the arrows NEXT and PREV.
HTML
<div id="imagem-galeria">
{!! Html::image('img/quem-somos/galeria/foto-grande-1.jpg', 'Peças Colhedora de Cana', ['class' => 'img-main']) !!}
{!! Html::image('img/quem-somos/seta-direita.png', 'Seta Direita', ['class' => 'seta-direita'] ) !!}
{!! Html::image('img/quem-somos/seta-esquerda.png', 'Seta Esquerda', ['class' => 'seta-esquerda'] ) !!}
</div>
<div class="owl-carousel-galeria">
<div class="item change-image"><div class="square"></div> {!! Html::image('img/quem-somos/galeria/torcane-foto-thumb-1.jpg', 'Foto 1') !!}</div>
<div class="item change-image"><div class="square"></div> {!! Html::image('img/quem-somos/galeria/torcane-foto-thumb-2.jpg', 'Foto 2') !!}</div>
<div class="item change-image"><div class="square"></div> {!! Html::image('img/quem-somos/galeria/torcane-foto-thumb-3.jpg', 'Foto 3') !!}</div>
<div class="item change-image"><div class="square"></div> {!! Html::image('img/quem-somos/galeria/torcane-foto-thumb-4.jpg', 'Foto 4') !!}</div>
<div class="item change-image"><div class="square"></div> {!! Html::image('img/quem-somos/galeria/torcane-foto-thumb-5.jpg', 'Foto 5') !!}</div>
<div class="item change-image"><div class="square"></div> {!! Html::image('img/quem-somos/galeria/torcane-foto-thumb-6.jpg', 'Foto 6') !!}</div>
</div>
jQuery
// Próxima Imagem
$('.seta-direita').on(clickDeviceEvent, function(){
var imgAtual = $('.img-main').attr('src');
// Continuação...
});
The element .img-main is where the main photo goes.
I tried to use the next() and the prev() of jQuery, but I couldn’t.
What’s the way to do it ?
Solution
jQuery
var fotos = new Array();
fotos[0] = "foto-grande-1.jpg";
fotos[1] = "foto-grande-2.jpg";
fotos[2] = "foto-grande-3.jpg";
fotos[3] = "foto-grande-4.jpg";
fotos[4] = "foto-grande-5.jpg";
fotos[5] = "foto-grande-6.jpg";
// Próxima Imagem
$('.seta-direita').on(clickDeviceEvent, function(){
var imgAtual = $('.img-main');
fotoAtual = fotoAtual + 1;
if(fotoAtual == 6)
fotoAtual = 0;
imgAtual.attr('src', urlBase + '/img/quem-somos/galeria/' + fotos[fotoAtual]);
});
// Anterior Imagem
$('.seta-esquerda').on(clickDeviceEvent, function(){
var imgAtual = $('.img-main');
fotoAtual = fotoAtual - 1;
if(fotoAtual < 0)
fotoAtual = 5;
imgAtual.attr('src', urlBase + '/img/quem-somos/galeria/' + fotos[fotoAtual]);
});
Or
var urlsImgs = $.map($(".owl-carousel-galeria").find('img'), function(obj,
return $(obj).attr('src').replace('thumb', 'grande');
});
// Próxima Imagem
$('.seta-direita').on(clickDeviceEvent, function(){
var imgAtual = $('.img-main');
fotoAtual++;
if(fotoAtual >= urlsImgs.length) {
fotoAtual = 0;
}
imgAtual.attr('src', urlsImgs[fotoAtual]);
});
// Próxima Imagem
$('.seta-esquerda').on(clickDeviceEvent, function(){
var imgAtual = $('.img-main');
fotoAtual--;
if(fotoAtual < 0) {
fotoAtual = (urlsImgs.length - 1);
}
imgAtual.attr('src', urlsImgs[fotoAtual]);
});
For Erick Gallani
Your code is too superficial. The element
.img-mainis the image that displays the current slide probably ? Because then grab thesrcand not the target image? What this template{!! .. !!}generates, elementsimg? I don’t know this template, there’s no tag for it either. I could post the generated code, maybe it would be easier for us. If they are generatedimgwould have no way of usingnext()andprev(). And what isimgAtual, some other code reads this variable ?– DontVoteMeDown
What jquery component is using? $('.img-main') is the container where the main image should be changing?
– Erick Gallani
@Erickgallani, exactly. I edited my post explaining this.
– Diego Souza
see if this can help you http://jsfiddle.net/8WTer/
– Thiago Friedman
@Dontvotemedown, the element
.img-mainis the main photo. Click on the slider photo and show in the main is already being done. But I want to do with arrows too. I am usingLaravel 5, did not put the tag why my need has nothing to do withLaravel.– Diego Souza
@Thiagofriedman, nice... but have to download Cycle. My last alternative is to use a plugin.
– Diego Souza
I get it, it’s just that I don’t know that syntax so if I had the tag I would search and understand, because I can’t tell if it’s server-side or not. Or, as I said if you post with the final code, the one generated by this template would solve it too. But ok.
– DontVoteMeDown
The syntax only assembles the
<img>. Not to write<img src=...>i do{!! HTML::image('caminho') !!}. And so it goes...– Diego Souza
I noticed that you added the solution in the question itself and accepted another as the best answer. Could you edit and add the solution as an answer? Don’t misunderstand me, I just think it would be better as an answer.
– Randrade
I couldn’t. Att, Diego.
– Diego Souza