I have a color picker that should allow to pick two different colours at once; it should work like this. touch the first color -> drag to the second color -> release finger on second color. The problem is that right now when I lift the finger from the screen the touchend event fires on the first color. It works fine with clicks, though.
$('.single-color').on('mousedown touchstart', function(e) {
e.preventDefault();
var index = $(this).attr('data-index');
$('#color1').val(index);
$('#color1').attr('data-color', $(this).css('background-color'));
console.log('touchstart - index: ' + $(this).attr('data-index'));
});
$('.single-color').on('mouseup touchend', function(e) {
e.preventDefault();
var index = $(this).attr('data-index');
$('#color2').val(index);
$('#color2').attr('data-color', $(this).css('background-color'));
console.log('touchend - index: ' + $(this).attr('data-index'));
});
.colors {
list-style: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.single-color {
height: 50px;
width: calc(50% - 10px);
margin: 0 5px 5px 5px;
float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="colors">
<li class="single-color" data-color="#4DB023" data-index="0" style="background-color: #4DB023">
</li>
<li class="single-color" data-color="#1E6B3D" data-index="1" style="background-color: #1E6B3D">
</li>
<li class="single-color" data-color="#233778" data-index="2" style="background-color: #233778">
</li>
<li class="single-color" data-color="#3098FF" data-index="3" style="background-color: #3098FF">
</li>
<li class="single-color" data-color="#FF0000" data-index="4" style="background-color: #FF0000">
</li>
<li class="single-color" data-color="#38889C" data-index="5" style="background-color: #38889C">
</li>
<li class="single-color" data-color="#483063" data-index="6" style="background-color: #483063">
</li>
</ul>
To replicate the problem look at the above snippet, setting the viewport to iPhone6 in the Chrome Resposive tool so it simulates touches.