I've got 2 questions if that's OK. I have a number of scripts running on a site i'm working on and I think I may be getting a clash with the image preload and another font resizing script. As I am new to javascript I have picked up the code from elsewehere. I am trying to get my head around it reading tutorials etc but am getting stuck when it comes to multiple scripts on the page
There are a number of scripts running: browser detect, png opacity, image preload, layer show/hide and a font resize.
here is the site
Q1 In IE5.5+ on the PC neither the font sizer nor the image preload is working - i think it is a clash of onload events. Can anyone suggest a fix?
Q2 I think there must be a better way to have my images preload. The current code is the dreamweaver version. Is there a better way?
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
I have this working fine, and I can append the preloaded image to a hidden div then fade the div in for a smooth effect.
Problem is I want to set this preloaded image as a css background image, not as a <img /> in a container. But if when the image is loaded, instead of .prepend() I do .css() and set the css property of a background-image to be the preloaded images URL, then when it carries on with displaying it the browser loads the image again. Rather than using the preloaded one.
I want the image to be a background image as I want it centered in the page background, even if it is too large for the viewport.
I got a script that rotates my images, but I have almost 300 in stock and it is preloading all 300 once the script is started. How do I get it to preload one at a time, or nothing at all? Code:
This isn't working and I can't figure out what I'm doing wrong:
var c_imgs = new Array( 'images/champascari.jpg', 'images/champfangio.jpg', 'images/champhawthorn.jpg', 'images/champhill.jpg', 'images/champsurtees.jpg', 'images/champlauda.jpg', 'images/champschumacher.jpg'); var pre_img; for (var i = 0; i < c_imgs.length; i++) { pre_img[i] = new Image(); pre_img[i].src = c_imgs[i]; }
If this code is correct, should I put it in a function and then call for it ?
I want to use an image as a CSS background-image so I used the Image constructor to load the image: [URL] but I noticed that the browser (Firefox) load the image from the URL and not from the memory when changing the background-image property (it takes about 1.5 seconds before showing the image, and every time I reload the page!)
Basically what I'm trying to achieve is when a new image is selected(clicked), the 'click' passes the new image name (and width, height) to the 'changeimg' function, I want this function to fade the current img so we can see the back ground wait img. then when the new image has preloaded successully, replace the current image and fade it back to full. It appears to do this mostly, but its not preloading the image, sometimes the contain will exapand to the new size and I'll see the image loading into it.
I'm wondering if I'm using the preload (new Image()) correctly, I cant locate any examples similar to what I'm doing. Most exapmles I see all appear to be to do with image rollovers. Which isn't what I need, I also do not want to pre load any images until they have been requested.
I'm trying to preload an image before it fades in and I'm using the following code to do so. Could someone please tell why it doesn't work? The layer fades in and then the image suddenly shows up.
I have a large image that I change by clicking on some small images to change it.
I use this code to preload images and then fade in, but it doesn't look nice. Once the images are cached into the computer the fading is perfect, but the first time it seems like it fades at the same time as it loads. I wonder if it could be done in some other way? Perhaps use a callback or preload all images into an array, but I'm new and don't really knows how to put i together yet?
a) preload all img's and background's on a given page
b) display an animated gif in the center of the original's img's or background's container
c) fade out showing each image once it's downloaded
d) as a consequence of (a) allow the page to render (show) quicker even if (depending on server speed, connection speed and user computer speed) the remaining images are still in a 'load state'.
e) is based on JQuery so not to increase page's footprint via adding Mootools, Prototype, YUI or the like (unless the additional 100KB or so is so worth it).
I've scouted Google and there a few out there but amazingly none seem to focus on doing this for a web page's image's but rather seem to focus on galleries/lightbox windows and so forth.
I have created a new theme for Rapidweaver and integrated some neat JQuery animated sliding panels and frankly I was feeling pretty chuffed with my efforts as I am far from a JQuery expert.[URL]..In the side panel on the left, I have embedded a Titter feed widget, lifting the code direct from Twitter. In Safari, Chrome, Opera and even jolly old IE this works fine. But Firefox has a fit and displays a blank page - or just plain won't load. If I remove the Twitter widget the page loads perfectly happily. If I disable Javascript in FF, the page loads (but there is no animation etc) - so there is clearly a JQ/Javascript/Twitter script issue going on here that is causing FF to freak out...
Of course the simple solution is not to add the Twitter feed, but since this is exactly one of the uses I was planning for this sliding panel, that's a fat 'non' option. All the JQuery code I have used for the theme has 'no conflict' calls and I have even added specific calls for specific code - so stuff like:
I find that either of these plugins work in isolation but together they are clashing. The first to be specified in my initialisation code works, the following doesn't. Initialisation code looks like this:
With image elements I can do <IMG src="..." onLoad="..."> where the onLoad is supposed to fire upon the image loading. Is there an event that I can trap for once the background image in <BODY background="...url..."> is loaded?
I plan to render a series of maps which sometimes take a while to compute (on the server) so I'd like to know when subsequent ones come in.
Failing that, can I assign an already loaded image to the background?
function go() { //alert("go?"); var pic=new Image(); pic.onload=yo; // method 1 //pic.addEventListener("load",yo,false); // method 2 pic.src="serenity.jpg"; } ---------------------------------
Code is in a file on it's own referenced from the xhtml. Using either of the two methods indicated the function yo doesn't get called.
Code works as expected in Firefox, Mozilla, Konqueror, IE. If I uncomment the alert in go() I can see that go does actually get called. Nothing comes up in Opera's Javascript console.
If I create an image element using the DOM methods and assign it an onload event handler, at what point is the image actually loaded and the event handler run?
So, given the following and assuming that "parent" references a node already in the document:
var elm = document.createElement("img"); elm.src = "myuglyface.jpg" // #1
addEvent(elm, "load", myHandler, false); // the standard cross-browser event adding mechanism
parent.appendChild(elm); // #2 Does the loading of the image begin at #1 or #2, ie when I first reference it or when it is added to the document? Can I even add an event handler at the point I do so?
I am trying to write a script that automatically changes an image on a web page on certain timings under the condition that a user never close or reload the page (for example, show black.jpg on Thursday 4:30-6:00 PM local time, show blue.jpg on Friday 3:15-5:00 PM local time and otherwise show red.jpg). The problem is that the black.jpg or blue.jpg never appears no matter how I change the numbers inside of, for example, "if (i>= 3204000 && i< 3205000)". Only the yellow.jpg and (approximately one second later) red.jpg. appear.
//DATE CONVERSION BEGINS: var today=new Date(); var dai=today.getDay(); var hrs=today.getHours(); var min=today.getMinutes(); var sec=today.getSeconds(); .....
The ones I find on Google all consist of white backgrounds that fade out to reveal an image... What I have at the moment are thumbnails that have hide/show div behaviors... But they look really boring at the moment and make my site boring... How I could make a png (a thumbnail border) fade in on the thumbnail whenever the mouse goes over it...
Been trying to get a short script I wrote to work 100%. Basically it checks to see if the main page image is =>375px and if it is shunts the text down below it. Its not a live site yet and due to it being so short I thought I would just copy and paste it here:
function checkImage(imageId) { if(document.getElementById) { var id = document.getElementById(imageId);
[code]....
The problem is with IE6, it randomly decides not to work without any sign from the debugger that anything is wrong. This is my first time using onLoad with an image, is there any quirks with it such as page load order (e.g. if the image finishes loading before the text loads this wouldn't appear to run?).
I change image.style.width inside a image.onload function. And surprisingly, I found that it runs the onload function on the same image again with the new style.width value. Javascript treats this as a new image! This is the same old image.
Is there a way to pervent it from runing onload the second time?