2017-05-22 67 views
0

基本上我需要div旋轉木馬服務圖像具有相同的高度div旋轉木馬服務內容。但由於某種原因,該腳本根本不會將div高度添加到div carousel-services-image。不能拉外高,並把它作爲'最小高度'

function carouselService() { 
 
    $('carousel-services-item').each(function() { 
 
    var ths = $(this), 
 
     thsh = ths.find('.carousel-services-content').outerHeight(); 
 
     ths.find('.carousel-services-image').css('min-height', thsh); 
 
    }); 
 
} 
 
carouselService();
<div class="carousel-services-item"> 
 
    <div class="carousel-services-content"> 
 
     <div class="carousel-services-composition"> 
 
     <div class="carousel-logo"><img src="img/nea-logo-black.png" alt="NEA"></div> 
 
     <h3 class="h3">Service Dos.</h3> 
 
     <ul class="carousel-services-list"> 
 
      <li>Lorem ipsum dolor. #1 - <strong>50 <i class="fa fa-dollar"></i></strong></li> 
 
      <li>Lorem ipsum dolor. #2 - <strong>50 <i class="fa fa-dollar"></i></strong></li> 
 
      <li>Lorem ipsum dolor. #3 - <strong>50 <i class="fa fa-dollar"></i></strong></li> 
 
     </ul> 
 
     <a href="#" class="button button-white">List of Services</a> 
 
     </div> 
 
    </div> 
 
    <div class="carousel-services-image" style="background-image: url(img/banner2.jpg);min-height: 350px;"></div> 
 

 
</div>

回答

1

1:一定要包括jQuery的

第二:你忘了.carousel-services-item

$(document).ready(function(){ 
 
    carouselService(); 
 
}); 
 
    
 
function carouselService() { 
 
    $('.carousel-services-item').each(function() { 
 
    var ths = $(this), 
 
     thsh = ths.find('.carousel-services-content').outerHeight(); 
 
     ths.find('.carousel-services-image').css('min-height', thsh +'px'); 
 
     
 
     
 
     //For check 
 
     alert(ths.find('.carousel-services-image').css('min-height')); 
 
    }); 
 
}
.carousel-services-image{ 
 
    background : red; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="carousel-services-item"> 
 
    <div class="carousel-services-content"> 
 
     <div class="carousel-services-composition"> 
 
     <div class="carousel-logo"><!--<img src="img/nea-logo-black.png" alt="NEA">--></div> 
 
     <h3 class="h3">Service Dos.</h3> 
 
     <ul class="carousel-services-list"> 
 
      <li>Lorem ipsum dolor. #1 - <strong>50 <i class="fa fa-dollar"></i></strong></li> 
 
      <li>Lorem ipsum dolor. #2 - <strong>50 <i class="fa fa-dollar"></i></strong></li> 
 
      <li>Lorem ipsum dolor. #3 - <strong>50 <i class="fa fa-dollar"></i></strong></li> 
 
     </ul> 
 
     <a href="#" class="button button-white">List of Services</a> 
 
     </div> 
 
    </div> 
 
    <div class="carousel-services-image" style="min-height: 350px;"></div> 
 

 
</div>

+0

謝謝!沒有注意到那個小點。 –

+0

@IliaBocharov不客氣。有時候小事會造成很大的問題。祝你有個美好的一天:-) ..請不要忘記接受答案 –