开发者

jQuery $(document).ready and svg-web window.onsvgload

jQuery of course requires everything to be inside

$(document).ready = function() {};

similarly, svg-web requires:

window.onsvg开发者_Python百科load = 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
});

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.

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.


Finally found this in the 'user manual':

$(document).ready(function() {
    window.addEventListener('SVGLoad', function() {
       // ready to work with SVG now
    }, false);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜