Adding animation to image change

廉价感情. 提交于 2019-12-25 02:59:34

问题


I have just implemented an extension in opencart which allows me to click on a thumbnail to change the main image, the only problem is, is just changes the image which no animation or transition effect at all, I would to make it so that the images slide in, is there anyway to add to the code I already have so that I can do that?

Here is the code for the mod:

<file name="catalog/controller/product/product.php">
        <operation>
            <search position="after"><![CDATA['popup' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')),]]></search>
            <add><![CDATA[// BOF om_Thumb_image_swap.xml
'addthumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height')),
// EOF om_Thumb_image_swap.xml]]></add>
        </operation>
    </file>

    <file name="catalog/view/theme/nthwondr_2013/template/product/product.tpl">
        <operation>
            <search position="before"><![CDATA[<?php echo $footer; ?>]]></search>
            <add><![CDATA[<!-- BOF om_Thumb_image_swap.xml -->
<?php if ($images) { ?>
<script type="text/javascript"><!--
$(function(){
    var imgs = <?php echo json_encode($images); ?>;
    var html = '';
    $.each(imgs,function(i,image){
        html += '<div class="image" style="display:none;"><a href="' + image.popup + '" title="<?php echo $heading_title; ?>" class="colorbox">';
        html += '<img src="' + image.addthumb + '" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" /></a></div>';
        $('.image-additional').before(html);
        html = '';
    })
    html = '<a href="<?php echo $popup; ?>" title="<?php echo $heading_title; ?>">';
    html += '<img src="<?php echo $thumb; ?>" width="<?php echo $this->config->get('config_image_additional_width'); ?>" height="<?php echo $this->config->get('config_image_additional_height'); ?>" title="<?php echo $heading_title; ?>" alt="<?php echo $heading_title; ?>" style="padding-left: 2px;" /></a>';
    $('.image-additional').prepend(html);
    var images = $('div.left .image');
    var thumbs = $('.image-additional a');
    thumbs.removeClass('cboxElement').removeClass('colorbox');
    images.children('a').colorbox({rel:'colorbox'});
    thumbs.on('click',function(e){
        e.preventDefault();
        images.hide();
        images.eq(thumbs.index(this)).show();
    });
});
//--></script>
<!-- EOF om_Thumb_image_swap.xml -->
<?php } ?>]]></add>
        </operation>
    </file>

Any help would be greatly appreciated, thanks guys.


回答1:


You can use this,

thumbs.on('click',function(e){
        e.preventDefault();
        images.hide('slide', {direction: 'left'}, 1000);
        images.eq(thumbs.index(this)).show('slide', {direction: 'left'}, 1000);
    });


来源:https://stackoverflow.com/questions/23171568/adding-animation-to-image-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!