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 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack