Jump to content

help with altering JQuery script


webguync

Recommended Posts

I need some help in altering this JQuery script if possible. I script as it currently stands creates a bar at the bottom of the page with a message that fades away after 5 secs. To trigger the bar you have to click a button. I would like to alter that so you don't need to click the button. The bar fades in after 5 seconds. Everything else I like.

 

Here is the code

 

 

 
(function($) {
 
$.fn.bar = function(options) {
var opts = $.extend({}, $.fn.bar.defaults, options);
return this.each(function() {
$this = $(this);
var o = $.meta ? $.extend({}, opts, $this.data()) : opts;
 
$this.click(function(e){
if(!$('.jbar').length){
timeout = setTimeout('$.fn.bar.removebar()',o.time);
var _message_span = $(document.createElement('span')).addClass('jbar-content').html(o.message);
_message_span.css({"color" : o.color});
var _wrap_bar;
(o.position == 'bottom') ? 
_wrap_bar   = $(document.createElement('div')).addClass('jbar jbar-bottom'):
_wrap_bar   = $(document.createElement('div')).addClass('jbar jbar-top') ;
 
_wrap_bar.css({"background-color"  : o.background_color});
if(o.removebutton){
var _remove_cross = $(document.createElement('a')).addClass('jbar-cross');
_remove_cross.click(function(e){$.fn.bar.removebar();})
}
else{ 
_wrap_bar.css({"cursor" : "pointer"});
_wrap_bar.click(function(e){$.fn.bar.removebar();})
} 
_wrap_bar.append(_message_span).append(_remove_cross).hide().insertBefore($('.content')).fadeIn('fast');
}
})
 
 
});
};
var timeout;
$.fn.bar.removebar  = function(txt) {
if($('.jbar').length){
clearTimeout(timeout);
$('.jbar').fadeOut('slow',function(){
$(this).remove();
});
} 
};
$.fn.bar.defaults = {
background_color  : '#fff',
color  : '#000',
position   : 'top',
removebutton      : true,
time   : 5000 
};
 
})(jQuery);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.