问题描述
jQuery当然要求一切都在里面
jQuery of course requires everything to be inside
$(document).ready = function() {};
同样,svg-web要求:
similarly, svg-web requires:
window.onsvgload = function() {};
是否有一种正确,优雅的方式来组合这些不会引起任何问题?
Is there a correct, elegant way to combine these that doesn't introduce any problems?
推荐答案
您可以绑定函数以在相应的事件上运行,如下所示:
You can just bind the functions to run on the appropriate event, like this:
$(function() { //shortcut for $(document).ready(function() {
//stuff that needs the DOM to be ready
});
$(window).bind('svgload', function() {
//SVG stuff
});
使用两者都没有坏处,事实上这是适当的用法,总是使用你需要的事件,这没有什么不同 document.ready
vs window.load
当您需要准备好图像时,而不仅仅是DOM。
There's no harm is using both, in fact that's the appropriate usage, always use the event you need, this is no different from document.ready
vs window.load
when you need images ready, not just the DOM.
如果重要, svgload
在 onload
后发生在截至本答复时支持它的浏览器中,不确定当其他浏览器支持它时是否一致。
If it matters, svgload
happens after onload
in the browsers that support it as of the time of this answer, not sure if that'll be consistent when other browsers support it though.
这篇关于jQuery $(document).ready和svg-web window.onsvgload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!