1

jquerymobileと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 -->
4

2 に答える 2

3

これには、タッチ開始イベントとタッチ終了イベントを使用できます。

$('#test').bind('touchstart', function() {
    $(this).css('background-color', 'black');
});

$('#test').bind('touchend', function() {
    $(this).css('background-color', 'white');
});​

これが動作中のデモです

ネイティブ DOM イベントの詳細については、MDN webstiteを参照してください。

于 2012-11-13T10:33:42.843 に答える
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');
});
于 2014-11-10T19:27:10.817 に答える