2011-04-28 35 views
0

我想說如果運動是向下運動是那麼一定長度使圖像變暗的不透明度,但與此代碼我得到一個語法錯誤:if語句懸停語法錯誤消息

function touchMove(event) { 
     event.preventDefault(); 
     if (event.touches.length == 1) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120){ 
      curX = event.touches[0].pageX; 
      curY = event.touches[0].pageY; 
     ('1.png').hover(function() { 
      $(this).stop().animate({ "opacity": .5 }); 
     }} 
      // OPTIONAL ACTION: draw the results to the page 
      updateReadout(2) 
     } else { 
      touchCancel(event); 
     } 
    } 

回答

0

我給你的代碼JSLint

function touchMove(event) { 
    event.preventDefault(); 
    if ((event.touches.length === 1) && (swipeDirection === 'down') && (swipeLength >= 90) && (swipeLength <= 120)) { 
     curX = event.touches[0].pageX; 
     curY = event.touches[0].pageY; 
     ('1.png').hover(function() { 
      $(this).stop().animate({ 
       "opacity": '.5' 
      }); 
     }); 
     // OPTIONAL ACTION: draw the results to the page 
     updateReadout(2); 
    } else { 
     touchCancel(event); 
    } 
} 

有幾個語法錯誤(丟失);及除其他事項外)。此外,updateReadout(2)調用在if之外,然後是一個孤獨的else,所以我根據自己的想法解決了這個問題,但您應該仔細檢查。

+0

謝謝。我非常欣賞這一努力。 – dmccallum 2011-04-28 16:17:03

0

有關語法錯誤的更多細節將有所幫助。

乍一看好像你需要一套支架,以便將if語句

if ((event.touches.length == 1) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120)) { 

其次,你正在使用1.png選擇我認爲是圖像元素的src?在這種情況下,它應該是

$('IMG[src*=1.png]').hover(function() { 

但是,根據圖像名稱選擇是非常不可靠的。例如,上面的代碼可以匹配1.png和11.png,21.png等。如果你可以改變它作爲一個類或id選擇器,或者從被觸摸的元素遍歷DOM來找到圖像。

代碼中可能存在其他問題,但希望能夠解決語法問題。

0
if (event.touches.length == 1) && (swipeDirection == 'down') && (swipeLength >= 90) && (swipeLength <= 120){ 

應該

if (event.touches.length == 1 && swipeDirection == 'down' && swipeLength >= 90 && swipeLength <= 120){ 

括號問題

0

在這一部分:

('1.png').hover(function() { 
      $(this).stop().animate({ "opacity": .5 }); 
     }} 

以及固定(每Rory的答案)選擇,最後一行應該是});

$('IMG[src*=1.png]').hover(function() { 
    $(this).stop().animate({ "opacity": .5 }); 
});