jQuery delay()
kitt
posted @ 2013年10月10日 17:58
in 技术类 Tech
, 1252 阅读
If there's an object whose id = "svg1" && type = "image/svg+xml" in html, jQuery can be used like this to access its elements:
<object id="svg1" data="123.svg" type="image/svg+xml"></object> var svg1 = document.getElementById("svg1").contentDocument; $(svg1).find('#m > ellipse') .delay(500) .queue(function() { $(this).attr('fill', '#ff0000'); $(this).attr('stroke', '#ff0000'); $(this).dequeue(); }) .delay(5000) .queue(function() { $(this).attr('fill', '#0000ff'); $(this).attr('stroke', '#0000ff'); $(this).dequeue(); })
First get the DOM of the svg file. '#m > ellipse' means id = m and find its children tag <ellipse>. Delay 0.5s, then change some of its attributes, then delay 5s, then change attributes. Remeber to use .queue and dequeue().