/    Sign up×
Community /Pin to ProfileBookmark

mouse over script for multiple pages

Ok, I have a script that just make a picture mouseover but because different pages all use the same one its an outside .js file. Heres the code:

[CODE]

<!– Begin

if (document.images) {

nexton = new Image(120, 55);
nexton.src = “gnexton.gif”

nextoff = new Image(120, 55);
nextoff.src = “gnextoff.gif”

}

function img_act(imgName) {
if (document.images) {
imgOn = eval(imgName + “on.src”);
document [imgName].src = imgOn;
}
}

// –>

[/CODE]

the line in the html looks like this:

[CODE]<script language=”JavaScript” src=”mouseover.js”></script></head>[/CODE]

&

[CODE]
<A HREF=”gallery2.html” ONMOUSEOVER=”img_act(‘next’)” ONMOUSEOUT=”img_inact(‘next’)”><IMG NAME=”next” BORDER=”0″ ALT=”next” WIDTH=”120″ HEIGHT=”55″ SRC=”gnextoff.gif” ALIGN=”RIGHT”></a><br>
[/CODE]

all it does is turn the link “gnextoff.gif” into “gnexton.gif” when you mouse over. I’m trying to do the same thing on another page but with the images “gbackoff.gif” and “gbackon.gif”. I’m not sure how to do it though? Can I just add to that .js file or do I have to make another? I prefer to just add but don’t have enough Js knowledge to know what I’m doing… I tried a few things but they didn’t work….

thanks….

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@MjhLkwdOct 11.2005 — [CODE]<HTML>
<Head>
<Script Language=JavaScript>

function SwapImage(curr,eventDesc) {

tmpStr = '1/'+curr;
swap = eventDesc;
if (swap == 'over'){document.getElementById(curr).src=tmpStr+'2.jpg'}
if (swap == 'out'){document.getElementById(curr).src=tmpStr+'1.jpg'}
}

</Script>
</Head>
<Body>
<center>
<img src='1/A1.jpg' id='A' onmouseover="SwapImage('A','over')" onmouseout="SwapImage('A','out')" alt='This is the hover text'>
</center>
</Body>
</HTML>[/CODE]
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 11.2005 — ummm.... thats not exactly what I needed... though I'm sure I will later....

That produces a floating image and all I was trying to do was make it be a mouseover image. So when you put your mouse over gnextoff.gif it turns into gnexton.gif

thanks though!
Copy linkTweet thisAlerts:
@KorOct 11.2005 — in your external js file
[code=php]
var poff;
function roll(p){
poff = p.src.split('/')[p.src.split('/').length-1]
p.src = poff.split('off')[0]+'on'+poff.split('off')[1]
p.onmouseout=function(){
p.src=poff;
}
}
[/code]


In your html pages

<img src="gnextoff.gif" onmouseover="roll(this)">

...

<img src="gbackoff.gif" onmouseover="roll(this)">

...

<img src="whateveroff.gif" onmouseover="roll(this)">

...

If your pictures are in another folder, not in the same root:

[code=php]
var poff;
var root;
function roll(p){
root= p.src.split('/')[p.src.split('/').length-2]+'/';
poff = p.src.split('/')[p.src.split('/').length-1]
p.src = root+poff.split('off')[0]+'on'+poff.split('off')[1]
p.onmouseout=function(){
p.src=root+poff;
}
}
[/code]
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 11.2005 — Hey, that worked! (even though I dont understand how) Thanks A Bunch!

If I need to add any other pictures, what do I do? Is it just based on the files name or what?

Thanks again...

Trina
Copy linkTweet thisAlerts:
@KorOct 12.2005 — Hey, that worked! (even though I dont understand how) Thanks A Bunch!

If I need to add any other pictures, what do I do? Is it just based on the files name or what?

Thanks again...

Trina[/QUOTE]


You may use the function for as many pictures you want. The only limitations are:

  • - the images must be something like whatever[COLOR=Red]off[/COLOR].[I]ext[/I] and whatever[COLOR=Red]on[/COLOR].[I]ext[/I]

  • - the images must be all placed in the same folder


  • The code usus the [b]this[/b] self references, so that you don't need a name or an id. It uses only the path of the images
    Copy linkTweet thisAlerts:
    @BaptistKittyauthorOct 12.2005 — ok... thats cool... thanks again for all your help..... This will make life a lot easier on me...

    Trina
    ×

    Success!

    Help @BaptistKitty 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,
    )...