I have a click and show option on my website, basically 4 thumbnails and a main image, you click the thumb and it swaps with the main image, pretty standard stuff and all was well until I tried to integrate it into a responsive site.
This is my code -
<div id="imgHolder" style="z-index:10">
<div id="hotel_Pic_Area_Middle_M" style="z-index:30;">
<div style="position:relative; width:300px; height:200px; margin-left:auto; margin-right:auto; z-index:50;">
<?php
if ($f['Award'] == '1'){ ?>
<div style="position:absolute;z-index:100;width:70px; height:70px; padding:10px;"><?php
$award = "<img src='http://www.checksafetyfirst.com/site_images/hotel_Page_Awards/general_hotel_award.png' width='70' height='70' alt='CSF Award Winner, View All' />";
} else {
$award = "";
}?>
<?php if ($award=="") {
} else { ?>
<?php echo $award ?>
</div>
<?php } ?>
<span><img class="HomeFeaturedImages3" src="http://www.checksafetyfirst.com<?php echo $f['Foto1_Hot']?>" alt="" border="0" width="300" itemprop="image" /></span>
</div>
</div>
<div id="hotel_Pic_Area_Middle" style="z-index:30;">
<div style="position:relative; width:430px; height:285px; z-index:50;">
<?php
if ($f['Award'] == '1'){ ?>
<div style="position:absolute;z-index:100;width:70px; height:70px; padding:10px;">
<?php
$award = "<img src='http://www.checksafetyfirst.com/site_images/hotel_Page_Awards/general_hotel_award.png' width='70' height='70' alt='CSF Award Winner, View All' />";
} else {
$award = "";
}?>
<?php if ($award=="") {
} else { ?>
<?php echo $award ?>
</div>
<?php } ?>
<span><img class="HomeFeaturedImages3" src="http://www.checksafetyfirst.com<?php echo $f['Foto1_Hot']?>" alt="" border="0" height="338" width="520" itemprop="image" /></span>
</div>
</div>
</div>
So Im trying to control that by using this below -
<script>
$(window).resize(function() {
if ($(window).width() < 660) {
var mainImage = $("#imgHolder hotel_Pic_Area_Middle_M span img");
$("a.showImg").click(function(e){
e.preventDefault();
var currImage = $(this).children('img');
var oldMainImageSrc = mainImage[0].src;
mainImage[0].src = currImage[0].src;
currImage[0].src = oldMainImageSrc;
//mainImage.src = $(this).children('img')[0].src;
});
}
else {
var mainImage = $("#imgHolder hotel_Pic_Area_Middle span img");
$("a.showImg").click(function(e){
e.preventDefault();
var currImage = $(this).children('img');
var oldMainImageSrc = mainImage[0].src;
mainImage[0].src = currImage[0].src;
currImage[0].src = oldMainImageSrc;
})}});
</script>
https://www.checksafetyfirst.com/mobile/hotel.php?hotel_ID=246328&Type=3&Resort=252
The reason for doing it like this is because when the page was viewed on a ipad it didnt work, but on a mobile it did, and I think its because this part of the code is first and when its in tablet view the other part of the code doesnt get executed -
<div id="hotel_Pic_Area_Middle_M" style="z-index:30;">