我試圖淡化divs,因爲我以10%的速度拖慢了它們。然而,如果我快速移動鼠標,它會立即變黑,並且會有一些淡色方塊。在jquery中延遲ondragover的效果/ javascript
問:如何讓方塊慢慢地向黑色褪色10%,但當用戶不再拖動鼠標時能夠停止。
在此先感謝,我試過諸如.delay函數等技術沒有成功。
(function() {
//When the mouse drags over the class cell, lower the opacity by 10%
$('.cell').on('dragover', function() {
var $currentOpacity = $(this).css("opacity");
$currentOpacity -= 0.1;
$(this).css('opacity', $currentOpacity);
});
})();
#grid-container {
width: 398px;
height: 25px;
font-size: 0;
background-color: black;
position: absolute;
}
.cell {
margin: 0.5px;
height: 5mm;
width: 5mm;
background-color: white;
display: inline-block;
z-index: 0;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div id="grid-container">
<div class="row line-1">
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
<div class="cell"></div>
</div>
</div>
</body>
</html>