dsdsm2016 2013-12-15 01:43
浏览 33
已采纳

jquery缩放,动态变化的图像

I use jquery zoom to display the image of a tshirt and allow my users to zoom it.

Recently, i have added an option to select the color of the t-shirt. After clicking on a color, i have a script that will change the tshirt image with the corresponding color. The problem is that when a color is selected, the zoomed image will still use the default image (black color).

I need to find a way to tell jquery.zoom.js that the image has changed if the user clicked a color

You can test it yourself and see the problem here: https://www.no-gods-no-masters.com/test.php Just click on red color then move your mouse over the tshirt - the color is still black.

Source of the jquery plugin used here: https://www.ni-dieu-ni-maitre.com/scripts/jquery.zoom.js

Color-switching script:

$.ajax({
  type: "post",
  url: "tshirt_ajax.php?checkshop=" + checkshop + "&checkproducttype=" + checkproducttype + "&stockcolor=" + stockcolor + "&currentsize=" + currentsize,
  beforeSend: function(){
    $('#productColor10462727').val(stockcolor);
  },
  success: function(data){
    $('select#size').html(data);
    $('#tshirtimg').attr('src', 'https://www.ni-dieu-ni-maitre.com/images/16176162_' + stockcolor + '_2/t-shirt-couleur.png');
    $('#size').coreUISelect('update');
  }
});

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongmei5168 2013-12-15 04:17
    关注

    The plugin appends an img with CSS class zoomImg to the element(s) on which you call zoom. One option is to alter the src of this img. In your example page, place the following code in the success callback.

    $('#ex1 .zoomImg').attr('src', 'https://www.ni-dieu-ni-maitre.com/images/16176162_' + stockcolor + '_2/t-shirt-couleur.png');
    

    This solution, however, depends on the implementation of the plugin. You're probably better off replacing the existing img when the user chooses the color, then calling zoom on the new img.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 怎么获取下面的: glove_word2id.json和 glove_numpy.npy 这两个文件
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug