/    Sign up×
Community /Pin to ProfileBookmark

Combining two JavaScripts

Ok, this should be quite simple, but i cant get the code to work correctly at all, and its really making me very frustrated.

This code is for an image rollover, and as you can see it uses three different image names:

<body onLoad=”slideit(‘slide’,’carImage’,1)”>

<img src=”slide18.jpg” name=”slide1″><br />
<img src=”slide20.jpg” name=”slide2″><br />
<img src=”slide21.jpg” name=”slide3″>

<script language=’javascript’>
<!–

var carImage1=new Image()
carImage1.src=”slide18.jpg”
var carImage2=new Image()
carImage2.src=”slide23.jpg”
var carImage3=new Image()
carImage3.src=”slide20.jpg”
var carImage4=new Image()
carImage4.src=”slide24.jpg”
var carImage5=new Image()
carImage5.src=”slide21.jpg”
var carImage6=new Image()
carImage6.src=”slide7.jpg”

function slideit(slideName, picName, numRollOvers)
{
var lenName = slideName.length;
var imgNum = numRollOvers;
var j = 0;

if (document.images)
{
with (document.images)
{
for (i = 0; i < length; i++)
{
if (document.images[i].name.substring(0,lenName) == slideName)
{
j++;
srcObj = eval(slideName + j) ;
srcObj.src = eval(picName + imgNum +”.src”);
imgNum+=2;
}
}
if (numRollOvers < 2) numRollOvers++
else numRollOvers = 1;
}
setTimeout(“slideit(‘” + slideName + “‘,'” + picName + “‘,” + numRollOvers + “)”,1000);
}
}

//–>
</script>

I would like to incorporate this code into the other one, which just fades an image into focus over a period of time

<img src=”slide18.jpg” name=”fadeinimage” style=”filter:alpha(opacity=0)”>

<script language=”JavaScript”><!–
function doFadeIn() {
if (document.fadeinimage.filters.alpha.opacity < 100) {
document.fadeinimage.filters.alpha.opacity=document.fadeinimage.filters.alpha.opacity+4
setTimeout(“doFadeIn()”,100)
}
}
doFadeIn()
// –>

</script>

Would appreciate some help on this

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisMar 25.2003 — Your swap happens every second. Your opacity changes by 4 every .1 second. That means it would take 2.5 seconds for your image to attain an opacity of 100. But you have already swapped the image twice. Ooops!

You can find a good example of the fade filter at http://msdn.microsoft.com/workshop/samples/author/dhtml/DXTidemo/DXTidemo.htm - select Transitions then look in the drop-down for Fade.
Copy linkTweet thisAlerts:
@NeverwhereauthorMar 25.2003 — awesome, thanks gil, i couldnt understand why it didnt work, but now this makes sense ?
×

Success!

Help @Neverwhere 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...