2017-04-05 47 views
2
變化

我的HTML:jQuery讓只在屏幕上

<div class="fi-container"> 
    <div class="fi-row"> 

     <div class="fi-cell"> <!-- content --> </div> 
     <div class="fi-cell"> <!-- content --> </div> 
     <div class="fi-cell"> <!-- content --> </div> 

    </div> 
</div> 

我的腳本:

$('.fi-cell').on('mouseenter', function(){ 
    $(this).parent().closest('div').css("background-color", 'yellow'); 
    }); 
$('.fi-cell').on('mouseleave', function(){ 
    $(this).parent().closest('div').css("background-color", 'inherit'); 
    }); 
}); 

我有一個頁面比屏幕上更廣泛。而且我的腳本只能處理在滾動到右側之前可以在頁面上看到的元素(當我滾動到右側時,腳本不能正常工作,並且背景色不會更改).DIV使用數據創建表。

我想background-color改變整個<div class='fi-row'>寬度,不僅是頁面加載的第一個寬度。

https://jsfiddle.net/7npL68jj/

+1

你能提供的jsfiddle,以顯示你的問題? –

+0

好的。稍等片刻。 – Kafus

+0

我編輯過的問題。請滾動右邊,你會看到:) – Kafus

回答

0

嘗試增加給你的CSS

.fi-row { 
    table-layout: fixed; 
    display: table; 
}; 

.fi-cell { 
    display: table-cell; 
}; 

我已經更新了你的提琴:https://jsfiddle.net/7npL68jj/4/

+0

嗯,這很有趣。它正在工作,但只是沒有爲'fi-cell'添加額外的代碼。謝謝。 – Kafus

+0

我已經清理了一下您的代碼,刪除了不必要的邊距,並添加了一個「框尺寸:邊框」以便更好地練習。你可以在我的回答中查看更新的小提琴。 –

+0

好的。非常感謝。 – Kafus