javascript - SVG donut-shape with access of both circles -
javascript - SVG donut-shape with access of both circles -
i want create svg donut shape (circle empty circle inside). want able access & resize both circles, eg via id attributes. allow animation.
i have considered 3 approaches none great:
complex path: not allow access of inner circle via #id outline stroke: possible complicated purpose (would have reposition increment stroke) clippath/mask: doesn't work compound path, outer boxis there way of doing this?
probably easiest way masks.
if working set of discrete donut sizes, utilize css , mask each size:
<svg width="500" height="500"> <defs> <mask id="bigmask"> <rect width="100%" height="100%" fill="white"/> <circle cx="250" cy="250" r="50"/> </mask> <mask id="smallmask"> <circle cx="250" cy="250" r="150" fill="white"/> <circle cx="250" cy="250" r="100"/> </mask> </defs> <circle id="donut" cx="250" cy="250" r="200" mask="url(#bigmask)"/> </svg>
css:
#donut:hover { mask: url(#smallmask); }
demo here
unfortunately can't modify size of circles css. "r" not (yet) property can manipulated css. need either utilize smil (svg) animation, or manipulate mask circles javascript:
<svg width="500" height="500"> <defs> <mask id="donutmask"> <circle id="outer" cx="250" cy="250" r="200" fill="white"/> <circle id="inner" cx="250" cy="250" r="50"/> </mask> </defs> <circle id="donut" cx="250" cy="250" r="200" mask="url(#donutmask)"/> </svg>
js
$("#donut").mouseenter(function(evt) { $("#outer").attr("r", 100 + math.random() * 100); $("#inner").attr("r", 100 - math.random() * 50); });
demo here
javascript svg
Comments
Post a Comment