据我所知,这种对图像样式的更改导致 LoadEvent 被触发。有人可以证实这一点吗?解释这个?这是 Firefox 3 上的 GWT。
Image image = new Image("image_src_URL");
image.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
double ratio = 0.5;
image.getElement().getStyle().setWidth(image.getWidth() * ratio, Style.Unit.PX);
Window.alert("You are in onLoad");
}
}
这段代码实际上位于onLoad方法内部,我可以清楚地看到它被输入了两次。有什么提示吗?还有另一种方法可以调整不会触发事件的图像大小吗? image.setWidth()
做同样的事情。
最佳答案
您是否需要 LoadHandler
多次触发?您可以取消注册它:
new LoadHandler() {
HandlerRegistration reg = image.addLoadHandler(this);
@Override
public void onLoad(LoadEvent evt) {
reg.removeHandler();
// Reset style
}
}
关于java - 更改图像样式会导致触发 LoadEvent 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5272870/