我正在使用jquery mobile和HTML5开发移动页面。
我想更改div颜色(最初颜色是黑色),当我按下(点击或点击)该div时,我想将该div的颜色从黑色更改为白色并且在我删除了我的点击后,即在我之后从那个div中取出我的手指,我想像以前一样恢复到黑色。
有没有这类活动?请帮我。谢谢。
<!--START:Initial state of Div Where i want to change color to white when i press that div and change back to normal after i remove my finger-->
<div class="colorBlack inactive"><div>
<!--END:Initial state of Div Where i want to change color to white when i press that div and change back to normal after i remove my hand-->
<!--START: Div class is changed to colorWhite,when i am tapping that div or i am holding that div with my finger-->
<div class="colorWhite active"><div>
<!--END: Div class is changed to colorWhite,when i am tapping that div or i am holding that div with my finger-->
<!--START: Div class is changed back to colorBlack,when i remove my finger -->
<div class="colorBlack active"><div>
<!--START: Div class is changed back to colorBlack,when i remove my finger -->
答案 0 :(得分:3)
您可以使用触摸开始和触摸结束事件。
$('#test').bind('touchstart', function() {
$(this).css('background-color', 'black');
});
$('#test').bind('touchend', function() {
$(this).css('background-color', 'white');
});
这是有效的DEMO
您可以在MDN webstite上找到有关原生DOM事件的更多信息。
答案 1 :(得分:0)
<button type="button" class="btn btn-default touchbtn">Test</button>
$('.touchbtn').bind('touchstart', function() {
$(this).css('background-color', 'black');
});
$('.touchbtn').bind('touchend', function() {
$(this).css('background-color', 'white');
});