2012-10-09 27 views
0

用手機開發手機應用程序,我面臨一個小問題。當觸摸按下我的任何按鈕時,我想在觸摸過程中交換背景,以便我可以向用戶提供有關正在發生的事情的視覺反饋。使用phonegap觸摸交換背景圖像?

但是,onmousedown事件永遠不會在android或任何其他事件中被觸發,除了onclick和onmouseup?我怎樣才能做到這一點?

我有我的JavaScript方法來交換工作的背景。

function touched(isTouched){ 
       console.log(isTouched); 
       if (isTouched) { 
        $('.blue_cell.firstCell').css("background-image", "url(images/cells/list-cell.png)");     
       } else { 
        $('.blue_cell.firstCell').css("background-image", "url(images/cells/blue-cell.png)"); 
       } 

      } 

而且我有我有我嘗試使用該事件測試按鈕:

<div class='blue_cell firstCell' onmouseup="touched(false)" onmousedown="touched(true)" 
     onmouseover="touched(true)" onfocusin="touched(true)"> 
    <div class='cellMainText'>openPopOver()</div> 
    <div class='cellIconText'>POP</div></div> 

感謝

回答

1

嘗試ontouchstart和ontouchend

<div class='blue_cell firstCell' ontouchstart="javascript:alert()" ontouchend="javascript:alert()"> 

,看看警報火災。

+0

太棒了!我正在研究ISCROLL的一些瘋狂的解決方法。非常感謝!出於好奇,你是否將所有有用的事件記錄在某處?我找不到任何關於ontouchstart/end的參考。我正在用javascript開始! – caiocpricci2

+0

http://dvcs.w3.org/hg/webevents/raw-file/tip/touchevents.html#list-of-touchevent-types –