2016-08-19 7 views
0

子要素のマスクとして機能する親要素のborder-radiusをアニメーション表示しようとしています。画像にposition:absoluteがない限り、これはうまくいきます。この場合は必要です。アクションで問題(Firefoxで正常に動作します):絶対配置された要素上にborder-radiusをアニメーション化しないWebkit

https://jsfiddle.net/dcm5kwvp/2/

編集:私は解決策を見つけた

setTimeout(function() { 
 
\t document.querySelector('.mask').classList.add('loaded'); 
 
}, 100);
.mask { 
 
    width: 100%; 
 
    height: 300px; 
 
    border-radius: 0; 
 
    transition: border-radius .3s ease; 
 
    overflow: hidden; 
 
    position: relative; 
 
    z-index: 1; 
 
} 
 

 
.mask.loaded { 
 
    border-radius: 0 0 50% 50%; 
 
} 
 

 
figure { 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    z-index: -1; 
 
}
<div class="mask"> 
 
<figure> 
 
    <img srcset="https://images.unsplash.com/photo-1470434151738-dc5f4474c239?dpr=1&auto=format&crop=entropy&fit=crop&w=1199&h=799&q=80&cs=tinysrgb"> 
 
</figure> 
 
</div>

+0

コード助けを求める質問は、質問自体に**それを再現するために必要な最短のコードを含める必要があります**好ましくは[**スタックスニペット**](HTTPSで://ブログ.stackoverflow.com/2014/09/introduction-runnable-javascript-css-and-html-code-snippets /)。あなたは[**サンプルまたはサイトへのリンク**]を提供していますが(http://meta.stackoverflow.com/questions/254428/something-in-my-web-site-or-project-doesnt-work-リンクが無効になる場合、あなたの質問は同じ問題を持つ他の将来のSOユーザには価値がないでしょう。 –

+0

もっと興味をそそる。プレビューのサイズを変更すると、実際にボーダー半径マスクが表示されます。おそらく誰かがCSSやJSを使ってそのリフローを引き起こす方法のアイデアを持っているかもしれません –

+0

私は自分の携帯電話にいますが、今答えを提供することはできませんが、私の意見ではこれはSVGのための完全な例です。レンダリングのためにパフォーマンスに遭遇する幅、高さ、ボーダー半径などのプロパティをアニメーション化しないようにしてください。 CSSアニメーションは、不透明度に固執して変換する必要があります。 – Ricky

答えて

1

コードスニペット。これはposition: absoluteが無効になっているWebkitエンジンのバグですoverflow: hidden

解決するには、-webkit-mask-imageをマスクを使用して要素に追加することをお勧めします。この場合、それは単一のピクセルであり、base64イメージとして埋め込まれます。

setTimeout(function() { 
 
\t document.querySelector('.mask').classList.add('loaded'); 
 
}, 100);
.mask { 
 
    width: 100%; 
 
    height: 300px; 
 
    border-radius: 0 0 0 0; 
 
    transition: border-radius .3s ease; 
 
    overflow: hidden; 
 
    -webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC); 
 
    position: relative; 
 
} 
 

 
.mask.loaded { 
 
    border-radius: 0 0 50% 50%; 
 
} 
 

 
figure { 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
}
<div class="mask"> 
 
<figure> 
 
    <img srcset="https://images.unsplash.com/photo-1470434151738-dc5f4474c239?dpr=1&auto=format&crop=entropy&fit=crop&w=1199&h=799&q=80&cs=tinysrgb"> 
 
</figure> 
 
</div>

+0

うわー、それはそんなに奇妙なバグです。解決策をありがとうございました。決して自分自身を思い付くことはなかっただろう。 – peirix

関連する問題