OpenSeadragon添加点击事件NextButton PresentButton



我想在nextButton和PresentButton中添加单击EventListener,并获取当前图像(通过viewer.source.getTileUrl()进行(。

但是,我正在接收TypeError: viewer.source is null。但它可以与getUrlBtn.addEventListener("click"[...]

一起使用

我在按钮上的Addhandler单击事件我做错了什么?

var viewer = OpenSeadragon({
  crossOriginPolicy: 'Anonymous',
  visibilityRatio: 1.0,
  showRotationControl: true,
  defaultZoomLevel: 1.0,
  minZoomImageRatio: 0.4,
  id: "osd-container",
  tileSources: ["images/T/1.dzi", "images/T/2.dzi", "images/T/3.dzi", "images/T/4.dzi"],
  sequenceMode: true,
  showReferenceStrip: false,
});
//works
var getUrlBtn = document.getElementById("getUrl");
getUrlBtn.addEventListener("click",function(e){
    console.log("getUrl: " + viewer.source.getTileUrl());
    currentFol.innerHTML = viewer.source.getTileUrl();
});
//TypeError: viewer.source is null
viewer.nextButton.addHandler("click",function(e){
    console.log("nextButton");
    currentFol.innerHTML = viewer.source.getTileUrl();
});
//TypeError: viewer.source is null
viewer.previousButton.addHandler("click",function(e){
    console.log("previousButton");
    currentFol.innerHTML = viewer.source.getTileUrl();
})
//I also tried but same error as above
viewer.nextButton.tracker.clickHandler = updateFol;
viewer.previousButton.tracker.clickHandler = updateFol;
var currentFol = document.getElementById("currentFol");
function updateFol(){
  console.log("next/previousButton");
  currentFol.innerHTML = viewer.source.getTileUrl();
}
<button id="getUrl">get current url</button>
<p><span id="currentFol"></span></p>

可能最好的方法是听"页面"事件:

viewer.addHandler('page', updateFol);

那有效吗?

相关内容

  • 没有找到相关文章

最新更新