Hello, I am learning how to create a jQuery plugin but I am having trouble with some parts, the plugin scrolls through the content in a container either left to right, bottom to top, and viceversa and it works fine however I now want to extend it’s functionality so I can stop and restart the scrolling and that is where I am having trouble, I currently have this
;(function($){
$.fn.tlakScroller = function(o) {
return this.each(function() {
var c = $(this);
o = $.extend( {}, $.fn.tlakScroller.defaultOptions, o );
op = '-';
ph = c.parent().height();
pw = c.parent().width();
switch ( o.dir ) {
case 'top':
o.l = ph - c.height();
break;
case 'bottom':
o.l = ph - c.height();
break;
case 'left':
o.l = pw - c.width();
break;
case 'right':
o.l = pw - c.width();
break;
default:
o.l = ph - c.height();
break;
}
object = setInterval(function(){
if ( o.startpixels == o.l || o.startpixels >= 1 ) {
op = setCount(op);
};
if ( op == '-' ) {
o.startpixels --;
} else {
o.startpixels ++;
};
c.attr('style', 'position: absolute;' + o.dir + ':' + o.startpixels + ';');
}, o.speed);
c.on('mouseover', function(){
clearInterval(object);
});
c.on('mouseout', function(){
object = setInterval(function(){
if ( o.startpixels == o.l || o.startpixels >= 1 ) {
op = setCount(op);
};
if ( op == '-' ) {
o.startpixels --;
} else {
o.startpixels ++;
};
c.attr('style', 'position: absolute;' + o.dir + ':' + o.startpixels + ';');
}, o.speed);
});
});
function setCount(d) {
switch ( d ) {
case '+':
d = '-';
break;
case '-':
d = '+';
break;
}
return d;
};
}
$.fn.tlakScroller.defaultOptions = {
dir: 'top',
scrollback : true,
speed: 100,
startpixels: 0
}
})(jQuery);
What I want to do is create a function that calls clearinterval and another one for setinterval on the target element, I tried creating functions but I always get undefined function in firebug, can someone give me an example on how I could create a public function to access and modify the variables of the object