0

I'm using a pretty cool JavaScript/jQuery library called OpenSeaDragon. It's for displaying deep zoom images. It also have a method for adding 'overlays', essentially creating a div and putting it over the image with coordinates though a viewer object. There's also a method for removing the overlays: https://openseadragon.github.io/docs/OpenSeadragon.Viewer.html#removeOverlay

viewer.removeOverlay(element or element id);

As the doc states regarding the input param: "A reference to the element or an element id which represent the ovelay content to be removed." I'm creating a whole bunch of overlays -- creating a grid out of rectangles -- so I've given them a class. Passing the class to this method doesn't work. So I'm trying to understand what they mean by "element". Is there a way I can use JQuery or JavaScript to select an "element" and pass it to the method? Or some such thing?

thanks

4

2 回答 2

3

它通常表示文档中的一个元素,即一个 DOM 节点。所以,a div,或a span,或类似的。

你可以很容易地用 jQuery 选择一个元素:

var $obj = $('#elementId');

然后从产生的 jQuery 对象中获取底层 DOM 节点:

var elm = $obj[0];
于 2015-12-30T18:45:36.853 回答
0

感谢大家。这是如何做到的:

var n = $(".gridcell").length
for(i=0; i<n; i++) {
    viewer.removeOverlay($(".gridcell")[0]);
}

起初我虽然可以遍历数组,在每个项目索引上依次调用 removeOverlay() 。这导致每次运行时都会删除一半的叠加层。因此,对于 16 次叠加,我必须运行 4 次。几分钟后它点击...每次你得到元素 $(".gridcell") 时,它都会返回一个新数组。

于 2015-12-30T19:14:07.213 回答