-5

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);
 });
General Grievance
  • 4,555
  • 31
  • 31
  • 45
user1999818
  • 71
  • 1
  • 6
  • possible duplicate of [How to create a jQuery plugin with methods?](http://stackoverflow.com/questions/1117086/how-to-create-a-jquery-plugin-with-methods) – Danubian Sailor May 31 '13 at 16:29

1 Answers1

3
(function($){
   $.fn.mySlider = function(parameters){
      // your code here
   }
})(jQuery)
maximkou
  • 5,252
  • 1
  • 20
  • 41