我試圖在圖像的單擊事件時從屏幕左下角向右上角移動圖像。現在,當圖像位於此位置(右上角)時,它應該移動到圖像點擊事件的屏幕右下角。但圖像不會從第二個位置移動(右上角)。任何建議爲什麼?Appcelerator動畫將圖像從一個位置移動到另一個位置
這是.xml文件的代碼:
<Alloy>
<View class="container">
<View class = " HeadingClass" >
<Label class="headingClass" top = "0%">Scrollable View And Animation Screen</Label>
</View>
<ScrollableView class = "scrollableViewClass" id="scrollableView">
<ImageView class="imgView1" id="imgViewId1"></ImageView>
<ImageView class="imgView2" id="imgViewId2"></ImageView>
<ImageView class="imgView3" id="imgViewId3"></ImageView>
<ImageView class="imgView4" id="imgViewId4"></ImageView>
<ImageView class="imgView5" id="imgViewId5"></ImageView>
</ScrollableView>
<View class="imageAnimationView" id="imageAnimation" >
<ImageView class="animateImageClass" id="animateImage"></ImageView>
</View>
</View>
</Alloy>
這是代碼。 js文件:
var args = $.args;
$.animateImage.addEventListener('click', function(e) {
if($.animateImage.top == "70%" && $.animateImage.left == "2%") {
var viewAnimate = Ti.UI.createAnimation({
top : "1%",
left : "80%",
duration : "2000" // top-right
});
}
else if ($.animateImage.top == "1%" && $.animateImage.left == "80%") {
var viewAnimate = Ti.UI.createAnimation({
top : "70%",
left : "80%",
duration : "2000"
});
}
if ($.animateImage.top == "70%" && $.animateImage.left == "80%") {
var viewAnimate = Ti.UI.createAnimation({
top : "70%",
left : "2%",
duration : "2000"
});
}
$.animateImage.animate(viewAnimate);
});
感謝MIGA!這工作很好! :) – SylieC