(function($){ $.fn.sideadv = function(options){ var defaults = { oparent : this, btnname : 'closebtn', posx : 300, posy : 200, timer : 30, stepx : 1, stepy : 1, limitx : false, limity : false }; var opt = $.extend(defaults,options); var _self = opt.oparent; _self.timer = null; clearinterval(_self.timer); _self.timer = setinterval(function(){ startmove(_self); },opt.timer); _self.hover(function(){ clearinterval(_self.timer); },function(){ _self.timer = setinterval(function(){ startmove(_self); },opt.timer); }); $('.'+opt.btnname).click(function(){ $(this).parent().css('display','none'); }) function startmove(_self){ var setw = $(window).width()-10; var seth = $(window).height(); var width = _self.height(); var height = _self.height(); var setleft = $(document).scrollleft() + opt.posx; var settop = $(document).scrolltop() + opt.posy; _self.css('left',setleft); _self.css('top',settop); if(opt.limitx){ opt.posx += opt.stepx; }else{ opt.posx -= opt.stepx; } if(opt.posx < 0){ opt.posx = 0; opt.limitx = true; } if(opt.posx >= setw - width){ opt.posx = setw - width; opt.limitx = false; } if(opt.limity){ opt.posy += opt.stepy; }else{ opt.posy -= opt.stepy; } if(opt.posy < 0){ opt.posy = 0; opt.limity = true; } if(opt.posy >= seth - height){ opt.posy = seth - height; opt.limity = false; } } } })(jquery);