2017-04-06 262 views
1

我需要一种方法来制作带有CSS3的缩放动画,并使用border-radius。但正如你可以看到下面,它不能很好地工作:CSS3缩放动画带边框半径

enter image description here

工作代码:https://jsfiddle.net/n5owxmch/

CSS:

* { 
    -moz-box-sizing: border-box; 
    -webkit-box-sizing: border-box; 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
} 

.item { 
    position: relative; 
    border-radius: 10px; 
    border: 1px solid #333; 
    margin: 2%; 
    overflow: hidden; 
    width: 540px; 
} 
.item img { 
    max-width: 100%; 

    -moz-transition: all 21s; 
    -webkit-transition: all 21s; 
    transition: all 21s; 
} 
.item:hover img { 
    -moz-transform: scale(1.1); 
    -webkit-transform: scale(1.1); 
    transform: scale(1.1); 
} 

HTML:

<div class="item"> 
    <img src="https://scontent.cdninstagram.com/t51.2885-15/s600x600/e35/17661731_634657496725091_8999479055321399296_n.jpg" alt="pepsi" width="540" height="548"> 

    <div class="item-overlay top"></div> 
</div> 

有没有办法解决这个问题?

+1

以何种方式它不能很好地工作? – LGSon

+1

你的例子对我很好,什么工作不好? –

+0

@LGSon在动画过程中,边框不像上图和jsFiddle中所示的那样是圆形的。 – xRobot

回答

2

从我的研究我转载了这只是在Chrome(边缘和Firefox工作正常)。为了解决这个问题,我添加了z-indexborder-radius的供应商前缀见下文。

通过添加z-index: 100;优先.item并使用z-index: 0;来优先化图像的优先顺序。基本上这会强制图像在.item之下。

而且我加厂商前缀(-moz--webkit-)为border-radius

-moz-border-radius:10px; /* add this */ 
    -webkit-border-radius: 10px; /* add this */ 

见片段:

* { 
 
    -moz-box-sizing: border-box; 
 
    -webkit-box-sizing: border-box; 
 
    box-sizing: border-box; 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
.item { 
 
    z-index: 100; /* add this */ 
 
    position: relative; 
 
    
 
    -moz-border-radius:10px; /* add this */ 
 
    -webkit-border-radius: 10px; /* add this */ 
 
    border-radius: 10px; 
 
    border: 1px solid #333; 
 
    margin: 2%; 
 
    overflow: hidden; 
 
    width: 540px; 
 
} 
 
.item img { 
 
    max-width: 100%; 
 
    z-index: 0; /* add this */ 
 
    -moz-transition: all 2s; 
 
    -webkit-transition: all 2s; 
 
    transition: all 2s; 
 
} 
 
.item:hover img { 
 
    -moz-transform: scale(1.1); 
 
    -webkit-transform: scale(1.1); 
 
    transform: scale(1.1); 
 
}
<div class="item"> 
 
    <img src="https://scontent.cdninstagram.com/t51.2885-15/s600x600/e35/17661731_634657496725091_8999479055321399296_n.jpg" alt="pepsi" width="540" height="548"> 
 

 
    <div class="item-overlay top"></div> 
 
</div>

+1

它在Chrome中正常工作已经,没有z-index的 – LGSon

+0

这部作品在歌剧:) – Huelfe

+0

由于'Z-index'只适用于定位元素(位置:绝对的,位置:相对或立场:固定的)一定还有别的什么是错的 – LGSon