試圖將類添加到img和標題(h3)以更改顏色。它正在向.test-shadow添加類,但是h3不起作用。試圖改變.closest/.find兄弟姐妹,但他們也不工作。想法?在滾動上更改顏色
\t /* highlight border of winner */
$('.img-winner').each(function(i){
var bottom_of_object = $(this).offset().top + $(this).outerHeight();
var bottom_of_window = $(window).scrollTop() + $(window).height();
/* If the object is completely visible in the window, animate border or box shadow */
if(bottom_of_window > bottom_of_object){
\t \t \t $(this).siblings('.test-shadow:first').addClass('greenit');
\t \t \t $(this).siblings('h3.test-who-us:first').addClass('green');
}
});
<ul class="2-column center test-images">
<li>
<h3 class="test-who-us">Medsite Medical</h3>
<div class="test-img">
<img class="img-winner" src="/wp-content/uploads/2016/07/test-desktop-us.png" alt="test-desktop">
<div class="test-shadow"></div>
</div>
</li>
<li>
<h3 class="test-who-them">Top competitor</h3>
<div class="test-img">
<img class="img-loser" src="/wp-content/uploads/2016/07/test-desktop-them.png" alt="test-desktop-competitors">
<div class="test-shadow"></div>
</div>
</li>
</ul>
嘗試使用'$(本).closest( '禮')。找到( 'H3')' – Mottie
,或者嘗試使用'$(本).parent( '禮')。找到( 'H3' )' – daymosik
或'$(this).parent()。siblings('h3.test-who-us:first')' – Iceman