473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Loading image when scrollbar moves

Hi,
I have 500 images.when clicking on one link it need to load this much images.Its loading
fine.My requirement is load the image only in the viewable area.when scrolling the scrollbar next
viewable area need to be loaded what i need to do


Pls help me
Its urgent


Thanks in advance
Jul 23 '09 #1
2 3438
gits
5,390 Expert Mod 4TB
so you have 500 images in one page? i would suggest a redesign to have some paging mechanism that is a bit more better to handle then. otherwise you would need to connect the scrolling-event to a load mechanism in a way that you react to the scrolloffset and calculate which images has to be loaded then. this is quite easy when all images have the same size and would be a bit more complicated when the (probably height) differs.

kind regards
Jul 23 '09 #2
Canabeez
126 100+
Here, try this, it should lead you to the right way.

Not sure how you can manage the src's, because you can't store them in the image and keep the image unloaded at the same time (Well, maybe you could store them as ALT text or a TITLE), but you decide.

But as gits said, if I were you, I'd consider redesign ;)

Good luck

Expand|Select|Wrap|Line Numbers
  1. function getPosition(Object)
  2. {
  3.     if('undefined' != typeof(Object.offsetParent))
  4.     {
  5.         for(var posX=0,posY=0;Object;Object=Object.offsetParent)
  6.         {
  7.             posX += Object.offsetLeft;
  8.             posY += Object.offsetTop;
  9.         }
  10.         return [posX,posY];
  11.     }
  12.     else
  13.     {
  14.         return [Object.x,Object.y];
  15.     }
  16. }
  17.  
  18. window.onscroll = function()
  19. {
  20.     var scrollTop = document.body.scrollTop;
  21.     var innerHeight = window.innerHeight;
  22.  
  23.     var images = document.getElementsByName("myImage");
  24.  
  25.     for(var i=0;i<images.length;i++)
  26.     {
  27.         var imageHeight = getPosition(images[i])[1];
  28.         if(imageHeight > scrollTop && imageHeight < (scrollTop + innerHeight))
  29.         {
  30.             images[i].src = images_src[i];
  31.         }
  32.     }
  33. }
  34.  
  35. var images_src = [];
  36.  
  37. for(var i=0;i<200;i++)
  38. {
  39.     images_src[i] = 'http://www.google.com/intl/en_ALL/images/logo.gif';
  40.     var img = document.createElement("img");
  41.     img.width = 276;
  42.     img.height = 110;
  43.     img.name = "myImage";
  44.     document.body.appendChild(img);
  45.     document.body.appendChild(document.createElement("br"));
  46. }
  47.  
Jul 23 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove...
1
by: tlyoung99 | last post by:
I have been working on this issue and can not seem to make any headway. Everything is beginning to run together. Any help would be greatly appreciated. Basically, my page looks just as I want it...
4
by: VR | last post by:
Hi, I am trying to have a menu item (which is an HTML img) to change as a mouse moves over it. So, my code looks something like this: <a onmouseover="ActivateImage('MyImage');"...
1
by: Tamir Kamara | last post by:
Hi, I have a page with several server controls (textboxes, datagrid, ...) which are positioned absolutely from the right of the page (like RIGHT: 25px; POSITION: absolute;). that works well if...
4
by: blackhawk | last post by:
I need to build a web page that has to potentially display a large amount of data in two grids on the same page. The HTML file with all of the formatting is about 7MB in size. This is too large...
1
by: sharma1985 | last post by:
Hi all ! I wanted to know the basic programming concepts of mouse programming as well as how can i zoom my image by moving the mouse pointer on a scrollbar. this should be worked like when...
10
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE...
0
by: Lloyd Sheen | last post by:
I have a table (produced from a datalist) that has an image followed by text. The image is a 32px scalled down version of the actual image. When the user moves over the image I want the image to...
4
by: CdnRebel | last post by:
Hi, I have double checked and triple checked, but I cannot figure out why my second image (the picture in div.top2) is not displaying. The spelling is right. I have attached the files. Also is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.