How to Create a Stickybar with "Close Button"?

[postlink]https://titanbloggers.blogspot.com/2012/03/how-to-create-stickybar-with-button.html[/postlink]

Make a stickybar with close buttonThe Stickybar or fixed Bar that we released was warmly welcomed. What we all have been searching for was a Close Button or Cancel button that would hide the bar display. May be not every visitor enjoys viewing that fixed bar at the top, so they deserve to be provided with an option to view or hide the bar. While viewing one of the Wordpress Blogs I found this button next to their updates bar. I managed somehow to fetch the script half broken. Making it work with blogger template was difficult because blogspot templates are programmed via XML and the rules of XML are really harsh when it comes to Character case. Debugging the script was difficult but Alhamdulillah the hard work paid off. You can see it Live just to the right of my Stickybar at the top. I am excited to share it with you all. Lets get to work!

Follow these easy steps:
  1. Go To Blogger > Design > Edit HTML

  2. Backup your template

  3. Search for this

]]></b:skin>

    4.   Just above it paste the following CSS code,

#tb_bar{
background:#333 url('https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkm4GB8D10cxhGlXvSPAbgv3XpI3bDlbo6YjDxWOr2fY5lvfwy62qdWt8QqphBFyzr_pqeOUPXfsH7Njzt0OLSQfyH1C1mn7ZCshn_JH6YCZ3-gLxAynofRItZtgql6dR9wIIsNGoTtP0/s400/stickybar.png') repeat-x;
width:100%;
margin:0 auto;
text-align:center;
padding:0px 0;
border-bottom: 1px solid #888888;
  -moz-box-shadow: #666666 0px 1px 3px;
  -webkit-box-shadow: #666666 0px 1px 3px;
  box-shadow: #666666 0px 1px 3px;
  z-index: 999;
height: 28px; position:fixed;
line-height: 1.85em;
vertical-align: baseline;
letter-spacing: 1px;
color:#fff;
font-size:13px;
font-weight:bold;
font-family: arial,"Helvetica",sans-serif;
}
#tb_bar a{
text-decoration:underline;
color:#E2E504;
}
#tb_bar a:hover{
text-decoration:none;
}
#tb_bar p {margin:0; list-style:none;}
#tb_bar img {vertical-align: middle;
      margin-right: 6px;}

    5.    Next search for </head>   and paste the following Javascript code just above it

<script type='text/javascript'>
//<![CDATA[
var tb_arr = new Array();
var tb_clear = new Array();
function tbFloat(tb) {
tb_arr[tb_arr.length] = this;
var tbpointer = eval(tb_arr.length-1);
this.pagetop = 0;
this.cmode = (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
this.tbsrc = document.all? document.all[tb] : document.getElementById(tb);
this.tbsrc.height = this.tbsrc.offsetHeight;
this.tbheight = this.cmode.clientHeight;
this.tboffset = tbGetOffsetY(tb_arr[tbpointer]);
var tbbar = 'tb_clear['+tbpointer+'] = setInterval("tbFloatInit(tb_arr['+tbpointer+'])",1);';
tbbar = tbbar;
eval(tbbar);
}
function tbGetOffsetY(tb) {
var mtaTotOffset = parseInt(tb.tbsrc.offsetTop);
var parentOffset = tb.tbsrc.offsetParent;
while ( parentOffset != null ) {
tbTotOffset += parentOffset.offsetTop;
parentOffset = parentOffset.offsetParent;
}
return tbTotOffset;
}
function tbFloatInit(tb) {
tb.pagetop = tb.cmode.scrollTop;
tb.tbsrc.style.top = tb.pagetop - tb.tboffset + "px";
}
function closeTopAds() {
document.getElementById("tb_bar").style.visibility = "hidden";
}
//]]>
</script>

   6.     Finally search for <body>  and just below it paste the following HTML code

<div id='tb_bar'> WRITE YOUR TEXT HERE
<span style='padding:0px; float:right'>
<img align='absmiddle' border='0' onClick='closeTopAds();return false;' src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6hvhlQ4JayloxvvctWFa_JNoIRLtjH0jWq85PWGBYhzDGYc8LC_y1txc0WZS3qGN5esZl4khG4ifPAUkoUw8MSS6kcSj4DvqUQHGpO92T7mPjqsMFdcUS8bplYlkgZjArVuyr0ITRREA/s400/cancel.png' style='cursor:hand;cursor:pointer;'/></span></div>
<br/><br/>

    To write an announcement, update news or notice to readers, just replace the yellow highlighted text with your message. If you wish to change the Close button image then simply replace the bolded black link with your button's link.

    7.     Save your template

    8.     You are all done!

Visit your blog to see it fixed to the top just beautifully with a close button waiting to be clicked!

How it works?

The close button when clicked triggers the function closeTopAds();  which then searches for function definition. The function is defined such that it sets visibility of bar to hidden. That's how the bar hides once the button is clicked and reappears only upon page refresh. Indeed a pretty neat way to make a user friendly bar.

Need help?

You are most welcomed to ask for any help if needed. If you wish to share the tutorial and scripts above with your readers then kindly attach attribution to TB blog. Peace and blessings pal! :)