Fix the position of a clip-path or mask

女生的网名这么多〃 提交于 2019-12-11 10:59:18

问题


I have this interface concept and I just don't know if it's possible. It's kinda hard to explain so I sketched it out.

I think I know how to accomplish some behaviour:

  • <header> position: fixed;
  • <nav> position: sticky (with a polyfill)
  • <section class="content box"> --- no idea really

I was hoping there would be some kind of way to add a clip-path to the content box that I could position: fixed. So that when the user scrolls the content box would peep trhough the area which was defined by the clip-path.

Looked into quite some options and thought I'd found a solution in webkit-mask-attachment but that property was nuked.

Any help is welcome. I prefer a pure CSS solution which has to work responsively.

Cheers, Bart!

PS. I have thought of a javascript solution where I monitor the scroll offset and change the class of <header> in which I set a height and overflow: hidden. But I really would prefer it if there was a CSS solution.

UPDATE 1

I'm on to something. Working in Firefox only since I'm using position: sticky and haven't bothered polyfilling it. It works when you scroll.... but if you scroll down and wait a couple of seconds somehow stuff gets repositioned or redrawn and the red header is shown fully again.

Any idea why this happens?

Try out this pen on Firefox: http://codepen.io/anon/pen/GJBxYw


回答1:


Ah, found it! Strange behaviour. In order to hide the svg object I set the css properties for svg to:

svg { display: none; }

Now somehow when scrolling this doesn't matter. But when you scroll the css rule kicks in. So in order to hide the svg object I changed the rule to:

svg {
  position: fixed;
  z-index: -1;
  top: 0;
  height: 0;
  width: 0;
}

And that seems to work. Don't know if there are better ways to go about hiding the svg object?

Try out this updated pen on Firefox: http://codepen.io/anon/pen/GJBxYw

Haven't done any serious FED since XHTML so I'm quite proud of myself, go easy on me :)



来源:https://stackoverflow.com/questions/31475725/fix-the-position-of-a-clip-path-or-mask

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!