fengyuanchen / viewerjs

JavaScript image viewer.
https://fengyuanchen.github.io/viewerjs/
MIT License
7.84k stars 1.24k forks source link

连续点击图片会报错 #376

Closed anyaooo closed 4 years ago

anyaooo commented 4 years ago

无法获取未定义或null引用的属性"style",地址在viewer.js 509行,setStyle 函数中

fengyuanchen commented 4 years ago

Are you using the latest version?

wongjiahau commented 4 years ago

I'm using "viewerjs": "^1.5.0".

I'm also facing this problem when I try to invoke the following code.

new Viewer(document.getElementById('images')).show()
Uncaught TypeError: Cannot read property 'style' of undefined
    at Viewer.open (webpack:///./node_modules/viewerjs/dist/viewer.js?:2652)
    at Viewer.show (webpack:///./node_modules/viewerjs/dist/viewer.js?:1742)
    at Viewer.show (webpack:///./node_modules/viewerjs/dist/viewer.js?:1721)
    at onClick (webpack:///./src/components/estore-page/components/image-grid.tsx?:73)
    at HTMLUnknownElement.callCallback (react-dom.development.js:188)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
    at invokeGuardedCallback (react-dom.development.js:292)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306)
    at executeDispatch (react-dom.development.js:389)
    at executeDispatchesInOrder (react-dom.development.js:414)
fengyuanchen commented 4 years ago

@wongjiahau Any online demo? I cannot reppear it.

Chisw commented 4 years ago

@wongjiahau Try this:

const viewer = new Viewer(
  document.getElementById('viewer-container'),
  {
    hide() {
      viewer.destroy()
    },
  }
).show()
wongjiahau commented 4 years ago

@wongjiahau Any online demo? I cannot reppear it.

Thanks for the reply, I'm not sure if it's because I'm mixing this usage with React and caused this problem.