okay, the scenario:
i have a header image which changes randomly across all pages in the
site. that works fine. i also have an image preloader within the random
header picker which theoretically loads the header image before the
rest of the graphical content on the page. however, what appears to be
happening, judging by the status bar messages, is that the banner
always loads last.
here's the random header code -
function random_header()
{
no=Math.random( )*14;
no=Math.round(n o);
no = no + 1;
bname = "banners/banner_" + no + ".jpg";
preload=new Image();
preload.src=bna me;
document.getEle mentById('rndim g').src=bname;
}
banners are all named sequentially, 'rndimg' is the blank header image
having its source changed.
any help is appreciated. thanks meantime :) 2 2074
bedges wrote: okay, the scenario:
i have a header image which changes randomly across all pages in the site. that works fine. i also have an image preloader within the random header picker which theoretically loads the header image before the rest of the graphical content on the page. however, what appears to be happening, judging by the status bar messages, is that the banner always loads last.
Why not randomise the banner on the server? Why rely on unreliable client
scripting when there seems to be zero benefit?
here's the random header code -
function random_header() { no=Math.random( )*14; no=Math.round(n o); no = no + 1; bname = "banners/banner_" + no + ".jpg";
Keep variables local if they don't need to be global. If your image names
are in the range 1 to 15 inclusive:
var bname = 'banners/banner_'
+ (Math.floor(Mat h.random()*15) + 1)
+ '.jpg';
Or using bitwise OR instead of Math.floor:
var bname = 'banners/banner_'
+ ((Math.random() *15 | 0) + 1)
+ '.jpg';
preload=new Image(); preload.src=bna me; document.getEle mentById('rndim g').src=bname;
Here you immediately load the image into the banner, you've given 'preload'
less than a millisecond to load and cache the image file. Also, it seems
you are running this onload so the image doesn't start loading until the
entire rest of the page has finished, making it more like a post-load
function. The function does not start downloading the image until it is
executed.
You are probably better to use a default image if scripting is not
available and replace the src with the random src using script:
<img src="noScriptDe fault.gif" alt="" name="bannerImg ">
<script type="text/javascript">
if (document.image s && document.images['bannerImg'])
{
document.images .bannerImg.src = 'banners/banner_'
+ ((Math.random() *15 | 0) + 1)
+ '.jpg';
}
</script>
Presumably the banner is right at the top, so it should load very near the
start anyway so any kind of preload is (almost) pointless. If you have
lots of script and CSS, then maybe to a preload right after the title
element will have a small benefit.
But the effect of multiple simultaneous connections will dilute the value
of pre-loading anyway. It was mostly useful for getting small button
images to load before big banners, but here you want to load the banner
first, which happens anyway.
Test and see.
}
banners are all named sequentially, 'rndimg' is the blank header image having its source changed.
--
Rob
unfortunately server-side randomising isn't an option in this case.
however i used a modified version of your code snippet in the
individual pages after the image appears and it seems to work a treat.
many thanks for the help. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Magic-chef |
last post by:
This rollover script is created by Image Reaady. When using IE and
especially with Win XP the images involved in the rollover disappear.
It happens gradually with one or two at first then all. Even a browser
refresh does not bring the images back.
I there a problem known issue with Image Ready rollover scripts and IE+XP?
<script TYPE="text/javascript">
<!--
function newImage(arg) {
|
by: David |
last post by:
Hi everyone,
I am trying to stop an image preload sequence by the click of a mouse but
have been unsuccessful trying several methods. Imagine this simple script
below that loads 50 images to cache. If the stopPreload() function is
activated and the ret val set to false, the preload() function still
continues to the end.
Any suggestions on how to stop the preload() function in its process, what
conditions are necessary?
|
by: sean.f.duffy |
last post by:
Hi!
I am an effectivebrand.com toolbar user and would love to add a
preloader to my toolbar, but am having problems doing this.
Is it possible to have javascript look at the URL of a webpage, then
follow links on that page, looking for images within that website (say
one page deep). Once found, could the images be preloaded into the
browser cache?
Many thanks for your help!
|
by: Ross |
last post by:
This page I am trying to create a preloader that hides all the other content
except the hidepage div until it loads...any ideas?
Or any preloaders that actually work?
http://www.nssdesign.scot.nhs.uk/home/index.php
|
by: abm |
last post by:
Hi. I am in great need of a preloader for my Flash web site. I have looked at a lot of tutorials and examples, but I can not seem to get it to work. How do I add a preloader to my existing Flash app??? (if you look at www.abmpic.com you will see that it takes too long to load without a preloader)
| |
by: sachaburnett |
last post by:
Hi everyone!
I'm new to Javascript and am finding so much useful information on this
group, so thanks to you all!
I have a question about preloading images for onmouseover/out effects
and found so many different ways to do it on the Net but am not sure
about something. Right now I have the following code inside my <head>
tag:
|
by: Lanky |
last post by:
I have noticed on sites that on a page a preloader will run and one or more flash movies will appear. Then the preloader does not reappear on subsequest revists to that page during the same browser session, as if the swf is loaded into memory and replays. Is my assumption correct and how exactly do I do this with my preloader?
|
by: streammalvern |
last post by:
Hi,
I am having a problem with a published Flash Movie. I included a preloader and the whole file size of the .swf is only about 1MB. If I go to the movie, it pauses even before the preloader appears on the screen. I have the preloader located on frame 1 & 2 of the first scene.
When I test the movie out of Flash and I view bandwidth and simulate a download, it shows that the movie is at Frame 0 for approximately 10 seconds. (I am...
|
by: donilourdu |
last post by:
hi,
I want to preload the image on page load using javascript
by,
Doni
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |