/    Sign up×
Community /Pin to ProfileBookmark

experiments with animation

doing some exercises to learn more about DHTML and javascript- while not important, i am just trying to get a foundation. MY question is why does the “slideBar” left and top styles remain the same for each mouse over…i am expecting it to move to where i am mousing over.

[code=php]
var subject;
var slideBar;
//happens onload
function makemenu()
{
var tags=document.getElementsByTagName(“a”);
for(g=0;g<tags.length;g++)
{
var tg=tags[g];
if(tg.addEventListener){
tg.addEventListener(“mouseover”,expand,false);
}else{
tg.setAttribute(“onmouseover”,expand);
}

}
slideBar=document.createElement(‘div’);
slideBar.id=”slideBar”;
slideBar.className=”whiteBar hide”;
document.getElementById(“menu1″).appendChild(slideBar);
}
function expand(e)
{
subject=this;
//define the event
var event=(ie)? window.event : e;
var hereX=this.style.left;
var hereY=this.style.top;
slideBar.className=”whiteBar”
slideBar.style.left=hereX
slideBar.style.top=hereY
if(this.addEventListener){
this.addEventListener(“mouseout”,collapseBar,false);
}else{
this.setAttribute(“onmouseout”,collapseBar);
}
}[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@s_b37Oct 11.2007 — can you post full code (your html as well, might be an id problem or something)

also, are you actually running makemenu() in the window.onload

it will not work unless the document has fully loaded
Copy linkTweet thisAlerts:
@Declan1991Oct 12.2007 — That probably won't work in IE 6 or less as far as I know. Using this in an event refers to the window in IE.
Copy linkTweet thisAlerts:
@s_b37Oct 13.2007 — yeah declan is right

to get the caller, use
[CODE]subject = event.target || event.srcElement[/CODE]
×

Success!

Help @mlecho spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...