Binding touch events and moving an element
Could you write something like this?

var limited = function( value, limit ){
    if (value &gt;= limit) { 
        return limit; 
    } else if (value &lt;= 0) { 
        return 0; 
    } else { 
        return value; 
    } 
}


then, when you need to work out move, just write move = limited( difference, limit );