Created
March 23, 2011 22:35
-
-
Save pec1985/884188 to your computer and use it in GitHub Desktop.
Titanium Mobile code for slider control functionality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Titanium Mobile code for slider control functionality | |
//---------------------------------------- | |
// @CJ_Reed 23rd Dec 2010 | |
var sliderView = Titanium.UI.createView({top:100,height:50,left: 40,width:240,backgroundColor:'#000'}); | |
var sliderButton = Titanium.UI.createView({width:96,borderRadius:5,backgroundColor:'#bbb',height:sliderView.height,left:sliderView.left,top:sliderView.top}); | |
Titanium.UI.currentWindow.add(sliderView); | |
Titanium.UI.currentWindow.add(sliderButton); | |
function unlock (){ | |
// function triggered when slider 'unlocks' | |
var msgbox = Titanium.UI.createAlertDialog({title:'Unlock', message:'unlock function fired...'}); | |
msgbox.show(); | |
}; | |
sliderButton.addEventListener('touchmove', function(e) | |
{ var moveX = e.x + sliderButton.animatedCenter.x - sliderButton.width/2; | |
if (moveX + sliderButton.width/2 >= sliderView.left + sliderView.width) | |
{ // button right-edge stop | |
moveX = sliderView.left + sliderView.width - (sliderButton.width/2); | |
} | |
else if (moveX - sliderButton.width/2 <= sliderView.left) | |
{ // button left-edge stop | |
moveX = sliderView.left + (sliderButton.width/2); | |
} | |
sliderButton.animate({center:{x:moveX,y:(sliderButton.top+(sliderButton.height/2))}, duration:1}); | |
}); | |
sliderButton.addEventListener('touchend', function(e) | |
{ var endX = sliderButton.animatedCenter.x + (sliderButton.width/2); | |
if (endX == sliderView.left + sliderView.width) | |
{ // button released at right-edge stop | |
unlock(); | |
}; | |
//springback | |
sliderButton.animate({center:{x:(sliderView.left+sliderButton.width/2),y:(sliderButton.top+(sliderButton.height/2))}, duration:300}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI - The values are updating property but the sliderButton isn't moving... I've traced moveX:
[INFO] moveX 88
[INFO] moveX 88.5
[INFO] moveX 89
[INFO] moveX 90.5
[INFO] moveX 90.5
[INFO] moveX 91.5
[INFO] moveX 92
[INFO] moveX 92.5
[INFO] moveX 93
[INFO] moveX 93.5
[INFO] moveX 94
[INFO] moveX 94.5
[INFO] moveX 95
[INFO] moveX 95.5
[INFO] moveX 96.5
[INFO] moveX 97.5
[INFO] moveX 98.5
[INFO] moveX 99
[INFO] moveX 99.5
[INFO] moveX 100
[INFO] moveX 100.5
[INFO] moveX 101
[INFO] moveX 101.5
[INFO] moveX 102.5
[INFO] moveX 102.5
[INFO] moveX 103
[INFO] moveX 104
[INFO] moveX 104.5
[INFO] moveX 105
[INFO] moveX 106
[INFO] moveX 106.5
[INFO] moveX 107
[INFO] moveX 107.5
[INFO] moveX 108
[INFO] moveX 108.5
sliderButton.animate isn't moving.
Ti SDK 3.3.0