0
我有一些HTML,看起來是這樣的:確定何時觸摸手勢離開目標元素
<div style="width: 50px; height: 50px; background: #f00" class="t"></div>
<div style="width: 50px; height: 50px; background: #0f0" class="t"></div>
<div style="width: 50px; height: 50px; background: #00f" class="t"></div>
<div style="width: 50px; height: 10px;" id="indicator"></div>
我如何編寫JavaScript,這將使#indicator
的background
顏色不管的#x
背景,#y
,或#z
當手指觸摸x
,y
和z
的矩形?
我可以做
$(".t").on('touchstart', function() {
$("#indicator").css('background', $(this).css('backgroundColor'));
});
這確實改變了顏色,但無法弄清楚如何把顏色回到auto
當手指離開div.t
的約束。
(我知道touchend
,但我希望它儘快恢復到默認的顏色作爲手指已經離開了矩形,不盡快手指拾起。)