HTML anchor tags have onClick events too. Did you try something like this? From here you can should be able to use the solutions that you found.
<a href="#" onclick='carousel("left", 99335)'><!--stuff here--></a>
Update:
I think this may be what you are looking for. Say you have three buttons (I'm just making up carousel
parameters, I have no clue what they mean):
<a href="#" onclick='carousel("left", 99335)'>Button 1</a>
<a href="#" onclick='carousel("right", 69235)'>Button 2</a>
<a href="#" onclick='carousel("left", 91235)'>Button 3</a>
We add a variable called isDone
to check if any processes are running or not. Modify the carousel
function like so (I explain the modifications using comments):
//isDone is initially set to true, because nothing is running.
var isDone = TRUE;
function carousel(direction, unique_id) {
//First of all, we can only execute the function is isDone is true. So we check for that:
if(isDone) {
//This implements the moment the function is called. We now know that it is currently in progress.
isDone = FALSE;
//This is the same as you had before
if (direction == 'right') {
$(document).ready(function(){
var displace_width = $('#carousel_ul_' + unique_id + ' li:last').outerWidth(true);
var scroll_width = $('#carousel_ul_' + unique_id + ' li:first').outerWidth(true);
//Here we set isDone equal to true when the .done is called:
$.when($('#carousel_ul_' + unique_id + ' li:last').clone().insertBefore('#carousel_ul_' + unique_id + ' li:first'), $('#carousel_ul_' + unique_id).css('left', '-=' + displace_width + 'px')).done(isDone = TRUE; $('#carousel_ul_' + unique_id + ':not(:animated)').animate({left: '+=' + scroll_width + 'px'}, 400, function(){$('#carousel_ul_' + unique_id + ' li:last').remove(); }));
});
} else {
$(document).ready(function(){
var displace_width = $('#carousel_ul_' + unique_id + ' li:first').outerWidth(true);
var scroll_width = $('#carousel_ul_' + unique_id + ' li:nth-child(2n)').outerWidth(true);
//Same thing here
$.when($('#carousel_ul_' + unique_id + ' li:first').clone().insertAfter($('#carousel_ul_' + unique_id + ' li:last'))).done(isDone = TRUE; $('#carousel_ul_' + unique_id + ':not(:animated)').animate({left: '-=' + scroll_width + 'px'}, 400, function(){$('#carousel_ul_' + unique_id + ' li:first').remove(); $('#carousel_ul_' + unique_id).css('left', '+=' + displace_width + 'px'); }));
});
}
}
//If isDone is not true, then we tell the user that and don't execute anything:
else {
alert("Not so fast! There is a process currently in progress.");
}
}
This way, because all of the buttons call the same carousel
function, they will only be executed if isDone
is set to true. Otherwise, the user will get an error alert and nothing will happen.