2016-11-22 223 views
2

我期待CSS動畫背景從大小background-size: cover;background-size: 120%懸停。我不能將背景從100%開始,因爲它開始在不同的設備/顯示器上垂直重複。但是,在這種情況下,transition:.5s;會停止任何類型的動畫。任何解決方法?Animate背景大小:縮放到背景大小:110%

代碼如下所示:

HTML

<div class="desktop-signs"> 
    <div class="image-box"> 
    <div class="col-md-4 block-service" id="block-illustration"> 
     <h2>ILLUSTRATION &amp; ANIMATION</h2> 
    </div> 
    </div> 
    <div class="image-box"> 
    <div class="col-md-4 block-service" id="block-website"> 
     <h2>WEBSITE DEVELOPMENT</h2> 
    </div> 
    </div> 
    <div class="image-box"> 
    <div class="col-md-4 block-service" id="block-game"> 
     <h2>GAME &amp; APP DEVELOPMENT</h2> 
    </div> 
    </div> 
</div> 

CSS

.__hero-container #services .block-service { 
    height: 800px; 
    background-image: url('../images/blockillustration.jpg'); 
    background-size: cover; 
    text-align: center; 
    color: #fff; 
    background-position: center; 
    opacity: 1; 

    -o-transition:.5s; 
    -ms-transition:.5s; 
    -moz-transition:.5s; 
    -webkit-transition:.5s; 
    transition:.5s; 
} 

.__hero-container #services .block-service:hover { 
    background-size: 110%; 
    opacity: 0.8; 
    cursor: pointer; 
} 
+1

過渡添加到:懸停爲好,也許? – Kyle

+0

'background-repeat:no-repeat'和'background-size:100%'? – Roberrrt

+0

不幸的是,將轉換添加到:hover元素不起作用:( 而我不能使用'background-repeat:no-repeat',因爲我得到的圖像不重複的黑色邊框。大小動態基於瀏覽器寬度使用Bootstrap! –

回答

5

當你意識到你不能從cover動畫爲任何其他值。

,你可以用假縮放僞元素的效果:

.block-service { 
 
    height: 800px; 
 
    color: #fff; 
 
    opacity: 1; 
 
    position: relative; 
 
    overflow: hidden; 
 
} 
 

 
.block-service:before { 
 
    content: ""; 
 
    background-image: url('http://placehold.it/400x400'); 
 
    background-size: cover; 
 
    background-position: center; 
 
    -o-transition: .5s; 
 
    -ms-transition: .5s; 
 
    -moz-transition: .5s; 
 
    -webkit-transition: .5s; 
 
    transition: all .5s ease; 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    z-index: -1; 
 
} 
 

 
.block-service:hover:before { 
 
    transform: scale(1.2); 
 
    opacity: 0.8; 
 
    cursor: pointer; 
 
}
<div class="desktop-signs"> 
 
    <div class="image-box"> 
 
    <div class="col-md-4 block-service" id="block-illustration"> 
 
     <h2>ILLUSTRATION &amp; ANIMATION</h2> 
 
    </div> 
 
    </div> 
 
    <div class="image-box"> 
 
    <div class="col-md-4 block-service" id="block-website"> 
 
     <h2>WEBSITE DEVELOPMENT</h2> 
 
    </div> 
 
    </div> 
 
    <div class="image-box"> 
 
    <div class="col-md-4 block-service" id="block-game"> 
 
     <h2>GAME &amp; APP DEVELOPMENT</h2> 
 
    </div> 
 
    </div> 
 
</div>

+1

你是我認識的最天才的蕪菁這種工作完美你是上帝 –

+2

這是一個鮮爲人知的事實,蘿蔔是所有根蔬菜中最聰明的 – Turnip

+0

我會吃更多的蘿蔔! –