JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2061
Number of posts: 5164

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
want to make it dynamic.... but how? Posted by praneeth on 22 Jul 2003 at 11:02 AM
hello ppl,

I am new to java scripr and need some help with this
preload images script.

The problem is that I use this script for loading
many pics on different html pages. So, I keep
pasting it in each page....... now this is redundent stuff,

So i was hoping to make it in to a single .js file and
send the images as parameters from with in the page.

But as i have problems with arrays i couldnt.
So can anyone solve my problem, make the script
in to a dynamic one which accepts the images as
parameters.

Here is the <head> part of the script..

<script language="JavaScript">
<!--
vers = 1.0;
// -->
</script>
<script language="JavaScript1.1">
<!--
vers = 1.1;
// -->
</script>
<script language="javascript">
<!--
function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}


// Loaded Pictures go here
var pics = new initArray(
"../1.jpg",
"../2.jpg",
"../3.jpg", <!-- All the images to be preloaded -->
"../4.jpg",
"../5.jpg",
"../6.jpg");


function transfer(param) {
location.href = "mainboard.html"; // URL of second page goes here **
}

function done() {
if (vers < 1.1)
transfer();
else
commence_loading();
}

function commence_loading() {
for (g=0;g<pics.length;g++)
eval('document.preload'+g+'.src = "'+pics[g]+'";');
}

// preload the status bar images
if (vers >= 1.1) {
blue = new Image();
blue.src = "../../images/scroll/blue.gif";
black = new Image();
black.src = "../../images/scroll/white.gif";
}

var loaded = new initArray(0);
for (h=0;h<pics.length;h++)
loaded[h] = 0;
num_loaded = 0;

function update(num) {
loaded[num]++;
if (loaded[num] == 2) {
if (vers < 1.1)
document.stats.status.value += "||";
else
eval('document.status'+num_loaded+'.src = "../../images/scroll/blue.gif";');
num_loaded++;
if (num_loaded == pics.length)
transfer();
}
}
// -->
</script>

Report
Re: want to make it dynamic.... but how? Posted by Weirdofreak on 22 Jul 2003 at 11:26 PM
I didn't bother to read all of that, so this may not work, depending on what exactly it does. What I'm putting will only preload the images, if you want to do anything else, you'll have to modify it. I'm also not entirely sure if it'll work, full stop. I'm not really an expert at calling javascripts, as I hardly ever need to. But here goes:

Basically, you want to create a function in the included file, that accepts one parameter- the image to preload. This will preload a single image. Then, set up a for loop that calls it with each image you want preloaded.
Report
Re: want to make it dynamic.... but how? Posted by lillu on 23 Jul 2003 at 1:49 AM
Hi,

This is a script from js-examples. It preloads a set of images, displays one, then you can click to display the rest one by one.

HTH,

Lillu

<html>
<head>
<!--
This file retrieved from the JS-Examples archives
http://www.js-examples.com
1000s of free ready to use scripts, tutorials, forums.
Author: JS-Examples - http://www.js-examples.com/
-->

<script language="JavaScript">
<!-- // preload photos
var mypix = new Array()
function preloadImages(){
for (i=0; i<preloadImages.arguments.length;i++){
mypix[i]=new Image();
mypix[i].src=preloadImages.arguments[i];
}
} // now allocate first photo
thispic = 0;
var isIE=document.all?true:false;
var isNS4=document.layers?true:false;
var isNS6=navigator.userAgent.indexOf("Gecko")!=-1?true:false;// now change photo to next
function processnext(){ // check if more pics
if(!document.images)return;
thispic=(thispic+1)%mypix.length;
if(isIE)
document.all.pic1.src = mypix[thispic].src;
else if(isNS4)
null;
else if(isNS6)
null;
}

function initImgs()
{
preloadImages("http://www.js-examples.com/js/pic1.gif",
"http://www.js-examples.com/js/pic2.gif",
"http://www.js-examples.com/js/pic3.gif",
"http://www.js-examples.com/js/pic4.gif",
"http://www.js-examples.com/js/pic2.gif",
"http://www.js-examples.com/js/pic3.gif");
}//-->
</script>
<style>
#photos {
position:absolute;
left:245px;
top:311px;
width:50;
height:50;
z-index:5;
background-color: #FFFFFF;
layer-background-color: #FFFFFF;
border: 1px none #000000;
}
</style>


</head>
<body onload="initImgs();">

<div id="photos">
<a href="javascript:processnext()"><img id=pic1 src="http://www.js-examples.com/js/pic4.gif" width="50" height="50" alt="Image Alt Text"></a>
</div>
<BR><center><a href='http://www.js-examples.com'>JS-Examples.com</a></center>
</body>
</html>

: hello ppl,
:
: I am new to java scripr and need some help with this
: preload images script.
:
: The problem is that I use this script for loading
: many pics on different html pages. So, I keep
: pasting it in each page....... now this is redundent stuff,
:
: So i was hoping to make it in to a single .js file and
: send the images as parameters from with in the page.
:
: But as i have problems with arrays i couldnt.
: So can anyone solve my problem, make the script
: in to a dynamic one which accepts the images as
: parameters.
:
: Here is the <head> part of the script..
:
: <script language="JavaScript">
: <!--
: vers = 1.0;
: // -->
: </script>
: <script language="JavaScript1.1">
: <!--
: vers = 1.1;
: // -->
: </script>
: <script language="javascript">
: <!--
: function initArray() {
: this.length = initArray.arguments.length;
: for (var i = 0; i < this.length; i++) {
: this[i] = initArray.arguments[i];
: }
: }
:
:
: // Loaded Pictures go here
: var pics = new initArray(
: "../1.jpg",
: "../2.jpg",
: "../3.jpg", <!-- All the images to be preloaded -->
: "../4.jpg",
: "../5.jpg",
: "../6.jpg");
:
:
: function transfer(param) {
: location.href = "mainboard.html"; // URL of second page goes here **
: }
:
: function done() {
: if (vers < 1.1)
: transfer();
: else
: commence_loading();
: }
:
: function commence_loading() {
: for (g=0;g<pics.length;g++)
: eval('document.preload'+g+'.src = "'+pics[g]+'";');
: }
:
: // preload the status bar images
: if (vers >= 1.1) {
: blue = new Image();
: blue.src = "../../images/scroll/blue.gif";
: black = new Image();
: black.src = "../../images/scroll/white.gif";
: }
:
: var loaded = new initArray(0);
: for (h=0;h<pics.length;h++)
: loaded[h] = 0;
: num_loaded = 0;
:
: function update(num) {
: loaded[num]++;
: if (loaded[num] == 2) {
: if (vers < 1.1)
: document.stats.status.value += "||";
: else
: eval('document.status'+num_loaded+'.src = "../../images/scroll/blue.gif";');
: num_loaded++;
: if (num_loaded == pics.length)
: transfer();
: }
: }
: // -->
: </script>
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.