更改图像样式是否会导致 LoadEvent 被触发?
据我所知,图像样式的更改导致 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()
的作用相同。
As far as I can tell, this change to the image style is causing the LoadEvent to be fired. Can someone confirm this? Explain this? This is GWT on Firefox 3.
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");
}
}
This code actually sits inside the onLoad method, and I can clearly see that it is entered twice. Any hints? Is there another way to resize the image that won't fire the event? image.setWidth()
does the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否需要多次触发
LoadHandler
?您可以注销它:Do you need the
LoadHandler
to ever fire more than once? You could de-register it: