with a session cookie
Code:
showhide:function(keyword, anim){
var thisbar=this, $=jQuery
var finalpx=(keyword=="show")? 0 : -(this.height-this.setting.peekamount)
var positioncss=(this.setting.position=="bottom")? {bottom:finalpx} : {top:finalpx}
this.$stickybar.stop().animate(positioncss, (anim)? this.setting.speed : 0, function(){
thisbar.$indicators.each(function(){
var $indicator=$(this)
$indicator.attr('src', (thisbar.currentstate=="show")? $indicator.attr('data-closeimage') : $indicator.attr('data-openimage'))
})
})
document.cookie=this.setting.id+'='+keyword+';'; // session cookie
thisbar.currentstate=keyword
},
toggle:function(){
var state=(this.currentstate=="show")? "hide" : "show"
this.showhide(state, true)
},
cookie:function(nme){
var re=new RegExp(nme+'=[^;]+','i');
if (document.cookie.match(re)){
return document.cookie.match(re)[0].split("=")[1];
}
return null;
},
init:function($, setting){
var thisbar=this,ck=this.cookie(setting.id);
this.$stickybar=$('#'+setting.id).css('visibility', 'visible')
this.height=this.$stickybar.outerHeight()
this.currentstate="hide"
setting.peekamount=Math.min(this.height, setting.peekamount)
this.setting=setting
if (setting.revealtype=="mouseover")
this.$stickybar.bind("mouseenter mouseleave", function(e){
thisbar.showhide((e.type=="mouseenter")? "show" : "hide", true)
})
this.$indicators=this.$stickybar.find('img[data-openimage]') //find images within bar with data-openimage attribute
this.$stickybar.find('a[href=#togglebar]').click(function(){ //find links within bar with href=#togglebar and assign toggle behavior to them
thisbar.toggle()
return false
})
setTimeout(function(){
thisbar.height=thisbar.$stickybar.outerHeight() //refetch height of bar after 1 second (last change to properly get height of sticky bar)
}, 1000)
this.setting=setting;
this.showhide(ck?ck:setting.onstartreveal?"show":'hide')
}
new option
Code:
var mystickybar=new expstickybar({
id: "stickybar", //id of sticky bar DIV
position:'bottom', //'top' or 'bottom'
revealtype:'mouseover', //'mouseover' or 'manual'
peekamount:35, //number of pixels to reveal when sticky bar is closed
// externalcontent:'stickybarcontent.htm', //path to sticky bar content file on your server, or "" if content is defined inline on the page
speed:200, //duration of animation (in millisecs)
onstartreveal:true // to reveal the stickybar on initialization
})
Bookmarks