スライダーにシンプルな背景画像スイッチャーがあります。
デフォルトでは、通常の環境 (.nenv) 画像は完全に表示されますが、環境 (.env) ビューをクリックしてからもう一度戻ると、jquery はその div 内のすべての背景画像を同じ画像に設定しています。
次のようになるはずです
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url('image1.png') no-repeat center;background-size:contain;"></div>
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url('image2.png') no-repeat center;background-size:contain;"></div>
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url('image3.png') no-repeat center;background-size:contain;"></div>
しかし、代わりに
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url('image1.png') no-repeat center;background-size:contain;"></div>
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url('image1.png') no-repeat center;background-size:contain;"></div>
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url('image1.png') no-repeat center;background-size:contain;"></div>
これがphp/jqueryです:
<div class="slides-container">
<?php foreach ($_productCollection as $_product): ?>
<script type="text/javascript" class="preserve">
jQuery(document).ready(function(){
jQuery('.env').click(function(){
jQuery('.singleartist-picture').removeAttr('style');
jQuery('.singleartist-picture').css('background', 'url(<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) .'/catalog/product/'. $_product->getData('enviromental'); ?>)');
jQuery('.singleartist-picture').css('background-size', 'contain');
jQuery('.singleartist-picture').css('background-repeat', 'no-repeat');
jQuery('.singleartist-picture').css('background-position', 'center');
//Buttons
jQuery('.env').css('color', '#009ab1');
jQuery('.env').css('text-decoration', 'underline');
jQuery('.nenv').css('color', 'black');
jQuery('.nenv').css('text-decoration', 'none');
})
jQuery('.nenv').click(function(){
jQuery('.singleartist-picture').removeAttr('style');
jQuery('.singleartist-picture').css('background', 'url(<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) .'/catalog/product/'. $_product->getData('normal_enviromental'); ?>)');
jQuery('.singleartist-picture').css('background-size', 'contain');
jQuery('.singleartist-picture').css('background-repeat', 'no-repeat');
jQuery('.singleartist-picture').css('background-position', 'center');
//Buttons
jQuery('.nenv').css('color', '#009ab1');
jQuery('.nenv').css('text-decoration', 'underline');
jQuery('.env').css('color', 'black');
jQuery('.env').css('text-decoration', 'none');
})
});
</script>
<div class="sartistpicture-<?php echo $_product->getId();?> singleartist-picture" style="background:url(<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) .'/catalog/product/'. $_product->getData('normal_enviromental'); ?>) no-repeat center;background-size:contain;"></div>
<?php endforeach; ?>
</div>
助言がありますか?:)