User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 374,173 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,433 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 448 | Replies: 0
Reply
Join Date: Jan 2008
Location: istanbul
Posts: 264
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Cross-browser javascript menu with few lines of code

  #1  
Mar 11th, 2008
Menu is about three things :
1) Position
2) Show-hide
3) Content

the Positining function is this :
function elementPosition(obj) {
var curleft = 0, curtop = 0;

if (obj.offsetParent) {
curleft = obj.offsetLeft;
curtop = obj.offsetTop;

while (obj = obj.offsetParent) {
curleft += obj.offsetLeft;
curtop += obj.offsetTop;
}
}

return { x: curleft, y: curtop };
}

the rest is Show-hide and content issues :

var _time_out = null;
function show_menu(ele,divToShow)
{
if(_time_out != null)
{
clearTimeout(_time_out);
}
var _pos = elementPosition(ele);
document.getElementById('dvMenu').style.left = _pos.x + "px";
document.getElementById('dvMenu').style.top = (_pos.y + 30) + "px";
document.getElementById('dvMenu').innerHTML = document.getElementById(divToShow).innerHTML;
document.getElementById('dvMenu').style.visibility = "visible";
}
function hide_menu()
{
_time_out = setTimeout("document.getElementById('dvMenu').style.visibility = 'hidden'",200);
}

the content container is this :

<div id="dvMenu" style="position:absolute;top:100px;left:100px;color:White;font-family:Verdana;font-size:11px;visibility:hidden;z-index:100;background-color:#2b2b2b" onmouseout="this.style.visibility='hidden'" onmouseover="clearTimeout(_time_out)"></div>

create your content divs :

<div id="foo">
<a href="http://www.foo.com" onmouseout="event.cancelBubble=true" onmouseover="this.parentNode.style.visibility='visible'>go to foo</a>
<a href="http://www.foo1.com" onmouseout="event.cancelBubble=true" onmouseover="this.parentNode.style.visibility='visible'>go to foo1</a>
</div>

menu buttons will be like this :

<img src="foo" onmouseover="show_menu(this,'foo')" onmouseout="hide_menu()" />
Serkan Şendur
MCAD.NET
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:24 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC