I'm currently working on a directive that shifts an element to the right whenever clicked. However, I want the element to keep moving as long as the button is pressed.
.directive("car", function(){
return {
restrict:"A",
link:function(scope,element,attrs,controller){
var left=0;
var car = angular.element(element[0].querySelector('.car'));
var move = function(e){
left+=10;
car[0].style.left = left+"px";
};
element.on("click", move);
}
};
})
My question is how can I continuously detect when the button is being pressed every half second and recall the move
function? Is there a way to achieve smooth movement?
Check out an interactive demo here: http://jsfiddle.net/vtortola/2m8vD/
I am unable to use jQuery for this particular task, but I am open to utilizing AngularJS modules like ngTouch or any other alternative.