2016-03-03 64 views
0

背景圖片我DIVCSS屬性:調整大小使用jQuery交通

.box { 
    background-image: url(images/img.jpg); 
} 

我已經選用this庫過渡效果。而且我想用比例尺在某些頁面上有效果。典型的語法規模元素是這樣的:

$('.box').mouseover(function() { 
    $(this).transition({ scale: 2.2 }); 
}); 

以上代碼沒有任何錯誤的作品,但它擴展在它的所有元素全DIV。

如何僅縮放背景圖像?

回答

1

我用JavaScript的解決方案。

$(document).on("mouseover", ".list", function(){ 
 
    $(this).css({"background-size":"150%", "transition":"all 0.5s ease"}); 
 
    \t }).on("mouseout", ".list", function(){ 
 
    $(this).css({"background-size":"100%", "transition":"all 0.5s ease"}); 
 
    });
.list{ width:/*100%*/ 90%; float:left; padding:15px 15px 15px; background:url("http://cdn.macrumors.com/article-new/2014/09/iphone_6_iphone_6_plus1.png") no-repeat center center ; height:150px; background-size:100% auto; transition:all 0.5s ease 1s;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
 
<div class="list"> 
 
xd 
 
</div>

+0

是的,這是我需要的!謝謝 – Abaza

0

試試這個,你有解決辦法。

.list{ width:/*100%*/ 90%; float:left; /*float:left;*/ border-right:3px solid #fff; padding:15px 15px 15px; background:url("http://cdn.macrumors.com/article-new/2014/09/iphone_6_iphone_6_plus1.png"); position:relative; margin:0 auto 1px; transition: all 0.7s ease 0s; -moz-transform: scale(1.0) !important; -webkit-transform: scale(1.0) !important; -o-transform: scale(1.0) !important; -ms-transform: scale(1.0) !important; transform: scale(1.0) !important; border-bottom:0 !important; height:150px;} 
 

 

 

 
.list:hover{background:url("http://cdn.macrumors.com/article-new/2014/09/iphone_6_iphone_6_plus1.png"); transition: all 0.7s ease 0s; -moz-transform: scale(1.04) !important; -webkit-transform: scale(1.04) !important; -o-transform: scale(1.04) !important; -ms-transform: scale(1.04) !important; transform: scale(1.04) !important;}
<div class="list">xd</div>

+0

謝謝您的回答。您的解決方案將全部DIV與其所有內容進行比例縮放但我只需要縮放背景圖片。另外我需要使用jQuery的transit插件來完成它。換句話說,這個解決方案不符合我的要求... – Abaza

+0

謝謝你的積極答覆。我正在開發基於jQuery的解決方案。 – Ankit

1

試試這個代碼。現在你找到解決方案。

.list{ width:/*100%*/ 90%; float:left; border-right:3px solid #fff; padding:15px 15px 15px; background:url("http://cdn.macrumors.com/article-new/2014/09/iphone_6_iphone_6_plus1.png") no-repeat center center ; position:relative; margin:0 auto 1px; transition: all 0.7s ease 0s; -moz-transform: scale(1.0) !important; -webkit-transform: scale(1.0) !important; -o-transform: scale(1.0) !important; -ms-transform: scale(1.0) !important; transform: scale(1.0) !important; border-bottom:0 !important; height:150px; background-size:100% 100%;} 
 

 

 

 
.list:hover{background:url("http://cdn.macrumors.com/article-new/2014/09/iphone_6_iphone_6_plus1.png") no-repeat center center ; transition: all 0.7s ease 0s; background-size:150% 150%;}
<div class="list">try this</div>

+0

感謝您的解決方案 - 它解決了我的要求的前半部分。但如何做到與jQuery Transit插件相同?我在我的項目中使用jQuery,並且一些支持者應該運行這種縮放效果。大多數情況下,縮放效果應該在沒有mousehover事件的情況下運行。例如,我需要在jQuery(document).ready事件中縮放背景圖像。 – Abaza