Edit: Fixed Error
Okay it's all done. Here is an example: http://masterscriptmaker.co.cc/dy/stretch.html. To do this you use the following structure:
HTML Code:
<div class="s_menu">
<ul>
<li style="background-color: violet;"><a href=""><span>Baltimore</span></a></li>
<li style="background-color: yellow;" class="s_menu_f"><a href=""><span>Newark</span></a></li>
<li style="background-color: blue;"><a href=""><span>Memphis</span></a></li>
<li style="background-color: orange;"><a href=""><span>San Antonio</span></a></li>
<li style="background-color: purple;"><a href=""><span>Miami</span></a></li>
<li style="background-color: gold;"><a href=""><span>Bronx</span></a></li>
</ul>
</div>
what ever <li> you want expanded add class="s_menu_f"
, as you can see it is in the second <li>. If you don't add it to anything, it defaults to the first.
To style it correctly you would add this css:
Code:
body {
padding: 0;
margin: 0;
}
.s_menu ul {
list-style: none;
padding: 0;
margin: 0;
}
.s_menu li {
display: inline;
float: left;
}
.s_menu a {
color: white;
text-decoration: none;
font: bold 13px "Lucida Grande", "Trebuchet MS", Verdana, Helvetica, sans-serif;
}
.s_menu a span {
display: block;
padding: 5px 30px;
cursor: pointer;
}
And now for the script, you would add this before the </body>
tag:
Code:
<script type="text/javascript">
/**Made By Master_Script_Maker**/
var s_menu={
by:[],
init:function() {
var t=this.get();
var f='', t2=[];
for(var i=0;i<t.length;i++) {
t2=t[i].getElementsByTagName("li");
for(var n=0;n<t2.length;++n) {
if(t2[n].className=="s_menu_f") {
f=n;
}
t2[n].onclick=(function(i, n) {
return function() {
s_menu.expand(i, n);
return false;
};
})(i, n);
}
this.menus.push([t[i], t2]);
if(!f) {
f=t2[0];
f.className="s_menu_f";
f=0;
}
setTimeout((function(t, i, f) {return function() {t.expand(i, f);};})(this, i, f), 200);
}
},
menus:[],
get:function() {
var t=document.body.getElementsByTagName("div");
var a=[];
for(var i=0;i<t.length;i++) {
if(t[i].className=="s_menu") {
a.push(t[i]);
}
}
return a;
},
expand:function(n, m) {
var f=this.menus[n][1][m];
var tem=f.parentNode.getElementsByTagName("li");
for(var i=0;i<tem.length;i++) {
tem[i].style.width='';
}
if(!this.by[n]) {
this.by[n]=f.offsetParent.clientWidth-tem[tem.length-1].offsetLeft-tem[tem.length-1].clientWidth;
}
f.style.width=f.childNodes[0].childNodes[0].offsetWidth+this.by[n]+"px";
}
};
function check() {
var div=document.createElement("div");
document.body.appendChild(div);
if(typeof console!="object") {
log=(function(d) {
return function() {
var temp=document.createTextNode(arguments.join(" "));
d.appendChild(temp);
d.appendChild(document.createElement("br"));
}
})(div);
} else {
log=console.log;
}
}
Object.prototype.join=function (a) {
var t="";
for(var i=0;i<this.length;i++) {
t+=this[i]+a;
}
return t;
};
check();
s_menu.init();
</script>
Feel free to edit anything to better suit you; also, I'll be glad to answer any questions you have about it.
Bookmarks