SitePoint Sponsor |
|
User Tag List
Results 1 to 6 of 6
-
Jan 7, 2008, 16:30 #1
- Join Date
- May 2006
- Location
- Kakiland
- Posts
- 732
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Preloading thumbs asking for advice and improvement
Hi.
This is my code:
PHP Code:function preloadImg(url) {
var temp=new Image();
temp.src=url;
}
function imgs(){
var el= document.getElementsByTagName('img');
for(var i=0,len=el.length;i<len;i++){
url= el.item(i).src.replace('thumbs', 'uploaded');
preloadImg(url);
alert(url);
addEvent(el.item(i),'click',popunder);
}
}
Bye.
-
Jan 7, 2008, 23:15 #2
- Join Date
- Sep 2006
- Posts
- 731
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jan 8, 2008, 01:57 #3
- Join Date
- May 2006
- Location
- Kakiland
- Posts
- 732
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the point
New version:
PHP Code:function preloadImg(urls) {
var tmp=[];
for(var i=0,len=urls.length;i<len;i++){
tmp[i]=new Image();
tmp[i].src=urls[i];
}
}
function imgs(){
var urls= [];
var el= document.getElementsByTagName('img');
for(var i=0,len=el.length;i<len;i++){
url= el.item(i).src.replace('thumbs', 'uploaded');
urls[i]=url;
addEvent(el.item(i),'click',popunder);
}
preloadImg(urls);
}
Bye.
-
Jan 8, 2008, 06:23 #4
- Join Date
- Sep 2006
- Posts
- 731
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jan 8, 2008, 14:15 #5
- Join Date
- May 2006
- Location
- Kakiland
- Posts
- 732
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sorry, but what's your idea about a preload function ?
Bye.
-
Jan 8, 2008, 16:01 #6
- Join Date
- May 2006
- Location
- Kakiland
- Posts
- 732
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In short:
PHP Code:function Thumb(){
var imgs= {};
function preloadImg(){
var el= document.getElementsByTagName('img');
for(var i=0,len=el.length;i<len;i++){
var tmp= el.item(i);
url= tmp.src.replace('thumbs', 'uploaded');
imgs[tmp.id]= new Image();
imgs[tmp.id].src=url;
imgs[tmp.id].title=tmp.title;
imgs[tmp.id].alt=tmp.alt;
addEvent(tmp,'click',popunder);
}
}
function box(largeImg){
var bodyEl= document.getElementsByTagName('body')[0];
bodyEl.appendChild(largeImg);
}
function popunder(e){
cancelClick(e);
var imgTarget= getTarget(e);
box(imgs[imgTarget.id]);
}
function init(){
if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode){return;}
preloadImg();
}
init();
}
addEvent(window,'load',Thumb);
Bookmarks