Try the following
// The right button in the slidebar moves it to the right
function shiftToRight() {
var cur = ($('#slideBar').position().left - $('#leftButton').outerWidth()) - $('.ingredient').outerWidth();
// Checks if movement will cause the slidebar out of right edge
if ($('#fixedPart').outerWidth() - cur > $('#slideBar').outerWidth()) {
cur = $('#fixedPart').outerWidth() - $('#slideBar').outerWidth();
}
$('#slideBar').animate({ left: cur}, { duration: 500 , easing: "swing" } );
};
var rightIntervalId;
$('#rightButton').mousedown(function() {
event.preventDefault();
rightIntervalId = setInterval(shiftToRight, 500);
}).mouseup(function() {
clearInterval(rightIntervalId);
}).click(function() {
shiftToRight();
});