1

If I call MagicZoomPlus.stop(); on active magiczooms I'll frequently get the error:

Uncaught TypeError: Cannot read property 'width' of null

At other times I'll get this error:

Uncaught TypeError: Cannot read property 'r' of undefined 

When that happens, mousing over the thumbnails triggers:

Uncaught TypeError: Cannot read property 't16' of null 

I've tried ...

  • calling MagicZoomPlus.stop() within the onload event
  • calling MagicZoomPlus.stop() within a setTimeout of different lengths
  • calling MagicZoomPlus.stop() after testing for the presence of MagicZoomPlus
  • testing an image for width/height before calling MagicZoomPlus.stop()
  • setting width/height on images via css and attributes before calling MagicZoomPlus.stop()

Here's a link to a jsfiddle that uses markup copied from an example on their docs page: http://jsfiddle.net/sjjju4x4/6/

If you 'run' the fiddle with the console open you'll sometimes get the error, sometimes not. If you reduce the timeout to 10 ms it'll happen more often

Seems like I can't post without a code sample, so here's the JS from the fiddle:

var output = document.getElementById('status');
setTimeout(function () {
    document.getElementById('status').textContent = '...............calling stop';
    MagicZoomPlus.stop();
}, 20);

Thanks in advance for any help or suggestions you can provide.

4

1 回答 1

0

在调用 MagicZoomPlus.stop() 之前,请确保 MagicZoom 实例已准备就绪。

可以使用以下 URL 中描述的“onready”回调来执行此操作:

https://www.magictoolbox.com/magiczoomplus/integration/#api

这是一些示例代码:

MagicZoomPlus.options = {
  'onready': function(id, isUpdated) {
     setTimeout(function () {
       document.getElementById('status').textContent = '...............calling stop';
       MagicZoomPlus.stop(id);
     }, 20);
  }
};

这是一个 jsfiddle,可帮助您查看代码:

http://jsfiddle.net/pg9f98z0/

于 2014-09-15T14:22:40.980 回答