0

I got an image created in js with a clip-path css attribute. I'm also creating an svg with a clip-path in svg, with a circle used as mask. Rendered it looks like this :

`<svg id="ayads-bubble-svg" height="0" width="0">
  <defs>
    <clipPath id="bubble-path">
      <circle cx="188" cy="117" r="229">
      </circle>
    </clipPath>
  </defs>
</svg>`

I'm changing circle r attribute on scroll, but my image clip isn't updated (while if I disable and enable clip-path in inspector it works).

I'll be really please if you guys have an idea Thanks a lot !

Adrien
  • 3
  • 2

1 Answers1

1

It's hard to say where your leprechaun sits, if we don't have all (related) pieces of code. However, I made an simple example which works just fine, for me (chrome v51.0+).

I hope this helps.

var circle = document.querySelector('circle')

window.addEventListener('scroll', function() {
  var delta = window.scrollY / (document.body.scrollHeight - window.innerHeight)
  circle.setAttribute('r', 50 - delta * 25)
})
html,
body {
  height: 200%;
}

svg {
  position: fixed;
}
<svg viewBox="0 0 200 200">
  <defs>
    <clipPath id="bubble-path">
      <circle cx="50" cy="50" r="50" />
    </clipPath>
  </defs>

  <rect width="100" height="100" clip-path="url(#bubble-path)" />
</svg>

Scroll Down
yckart
  • 32,460
  • 9
  • 122
  • 129