Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Javascript image problem

05 Aug 2011   #1
Stefany93

Windows 7 Ultimate
 
 
Javascript image problem

Hello colleagues,


I was trying to make an onMouseOver effect with one image with Javascript. It works perfectly fine, the only issue was, that when I mouse over the image, it generates the other one very slowly. So I decided to preload the images before using them and that way it is will be much faster. The only problem is that it doesn't work and I have no idea why . I mean the onmouse effect works, but the speed of loading the image is the same even without the preloading code. Can you please help me? Here is the JS code:

Code:
                      if(document.image){
			
			var pic1 = new Image();
			pic1.src = "http://farm6.static.flickr.com/5135/5515445106_d27e289646_m.jpg";
			var pic2 = new Image();
			pic2.src ="dimitar_shumen.jpg";
			}
			
			
			
			
			
			function mouse_over(){
			
		
			
			document.getElementById("pic1").src = "dimitar_shumen.jpg";
			
			}
			function mouse_out(){
			
			document.getElementById("pic1").src ="http://farm6.static.flickr.com/5135/5515445106_d27e289646_m.jpg";
			
			
			}
And the HTML code of the image I want to format:

Code:
<a href="http://www.flickr.com/photos/59988828@N03/5515445106/" title="dimitar_shumen by ChessAdmin, on Flickr"><img src="http://farm6.static.flickr.com/5135/5515445106_d27e289646_m.jpg"  alt="dimitar_shumen" id="pic1"  onmouseover="mouse_over()" onmouseout="mouse_out()"/></a>

If you need, I will also provide the code of the entire page, if necessary.

Thank you in advance!

Best Regards
Stefany


My System SpecsSystem Spec
.
06 Aug 2011   #2
Neutron16

Windows 8.1 ; Windows 7 x86 (Dec2008-Jan2013)
 
 

Script has to be inside <HEAD> tag.

You do preload images , but in function mouse_over() you load them again! And unless your browser is in Offline mode it will reload that picture.
Check this out. I have highlighted differences from your code
Code:
<HTML><HEAD>
<script language="JavaScript">
 if(document.images){
            
            var FRST = new Image();
            FRST.src = "http://farm6.static.flickr.com/5135/5515445106_d27e289646_m.jpg";
            var SCND = new Image();
            SCND.src ="dimitar_shumen.jpg";
            }
            
            function mouse_over(){
                        
            if (document.images) document.pic1.src=SCND.src;
            
            }
            function mouse_out(){
            
            if (document.images) document.pic1.src=FRST.src;
            
            
            }
</script>
</HEAD>
<BODY><a href="http://www.flickr.com/photos/59988828@N03/5515445106/" title="dimitar_shumen by ChessAdmin, on Flickr">
<img src="http://farm6.static.flickr.com/5135/5515445106_d27e289646_m.jpg"
 alt="dimitar_shumen" name="pic1"  onmouseover="mouse_over();return true;"
 onmouseout="mouse_out();return true;"/></a>
</BODY></HTML>
My System SpecsSystem Spec
06 Aug 2011   #3
Stefany93

Windows 7 Ultimate
 
 

Neutron16 thank you so much! you are great! Thank you!
My System SpecsSystem Spec
.

Reply

 Javascript image problem




Thread Tools





Similar help and support threads
Thread Forum
IE9 - Problem with javascript
Hello, I have IE9 on Win7 x64 PRO SP1. I have a problem with javascript on a lot of websites - it doesn't work on normal browse, but when I refresh page (CTRL+F5) everything is ok. I checked this in developter tools, and there are many communicates like this one: SCRIPT: Permission...
Browsers & Mail
javascript problem crops up
Hi, I'm new here-just wondering if someone can help me with a javascript issue? I'm using Firefox 3.something (I HAD updated to newest version but wouldn't work on site I needed it to) and occasionally the online portal for the college courses I'm taking will not even let me log in, and claims it's...
Browsers & Mail
Help with Javascript?
Hi guys, I'm working on a site for a school project, and I got a scrolling sidebar using some Javascript I borrowed from somewhere. The thing is, it scrolls horizontally as well as vertically. I have no idea how to code Javascript and was wondering if any of the whizzes on here could help? ...
Chillout Room
JavaScript help...
So I'm working on adding functions to my battery gadget, and one function I'm trying to add will bring the gadget to the front (make it appear above all other windows) once the battery gets down below 21% (I'll wind up adding a function too that will make it coincide with the user's setting for low...
Chillout Room
javascript
somebody can help me to find out good web for javascript tutorial or some reference on it.?? i'm tried to find out but didn't got a good one. your attention be my pleasure. thanks.
Chillout Room
JavaScript
Hello everyone. I have a question to the authors of this phorum.I really like the script that this site uses for image autoresizing.Can you please give me at least the name of this script cause i have been looking for something similar for some time now and still havent found anything. Thanks
Chillout Room

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 20:30.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App