This is my code and work properly, but I want to convert these code to a jquery plugin (mySlider). See Demo. How to do?
var _left = 1, _move = 0, _right = null;
_width = $('#main-slider li:first').width(),
_len = $('#main-slider li').size();
$('#main-slider ul').width(_width*_len);
$('#thmb-slider ul').width(_width*_len);
var auto_slide = setInterval(feature_slider, 5000);
function feature_slider(){
if(_right == 0) { _right = null; _left = 1; }
if(_left > 4) { _right = 4; _left = 0 }
_move = (_width*_left)*(-1);
if(_right) {
_right--;
_move = (_width*_right)*(-1);
}
$('#main-slider ul')
.css({'opacity':0})
.animate({left:_move,'opacity':1},900,'swing');
_left++;
}
$('#thmb-slider a').click(function(){
_left = $(this).index('#thmb-slider a');
clearInterval(auto_slide);
feature_slider();
auto_slide = setInterval(feature_slider, 5000);
return false;
});
$('#main-slider ul').hover(function(){
clearInterval(auto_slide);
},function(){
feature_slider();
auto_slide = setInterval(feature_slider, 5000);
});