JavaScript - Image Roll Over
I am trying to create a multiple image rollover and when you click on an image, the page will direct to a relevant external website. However only the first image changes when you rollover it, the other four images will not change. Any suggestions??
Code: <HTML><HEAD><TITLE>Monsters Inc Rollover Images</TITLE> <META content="text/html; charset=iso-8859-1" http-equiv=Content-Type> <SCRIPT language=Javascript type=text/javascript> <!-- var monstersincON = new Image; var sulley = new Image; var mike = new Image; var booON = new Image; var randallON = new Image; var monstersincOFF = new Image; var sulleyOFF = new Image; var mikeOFF = new Image; var booOFF = new Image; var randallOFF = new Image; monstersincON.src = "../images/monstersinc.jpg"; sulleyON.src = "../images/scully.jpg"; mikeON.src = "../images/mike.jpg"; booON.src = "../images/boo.jpg"; randallON.src = "../images/randall.jpg"; monstersincOFF.src = "../images/monstersincoff.jpg"; sulleyOFF.src = "../images/scullyoff.jpg"; mikeOFF.src = "../images/mikeoff.jpg"; booOFF.src = "../images/boooff.jpg"; randallOFF.src = "../images/randalloff.jpg"; /* Callout: This function takes two parameters, the version name (ON or OFF) and the image name. This makes it possible to handle all image swapping with only this one function. */ function swapImage(version, imagename){ if (document.images){ document[imagename].src = eval(imagename + version + ".src"); } } /* Callout: This function turns all images back to their 'off' versions. */ function rollOffAll(){ swapImage('OFF','monstersinc'); swapImage('OFF','sulley'); swapImage('OFF','mike'); swapImage('OFF','boo'); swapImage('OFF','randall'); } //--> </SCRIPT> </HEAD> <BODY bgColor=white> <DIV align=center><A onmouseover="swapImage('ON','monstersinc');" onmouseout=rollOffAll(); onclick="rollOffAll();return true;" href="http://.html"><IMG border=0 name=monstersinc alt="Monsters Inc" src="../images/monstersincoff.jpg" width=250 height=250></A> <HR> <BR><A onmouseover="swapImage('ON','sulley');" onmouseout=rollOffAll(); onclick="rollOffAll();return true;" href="http://www..html"><IMG border=0 name=sulley alt=Sulley src="../images/sulleyoff.jpg" width=175 height=225></A> <BR><A onmouseover="swapImage('ON','mike');" onmouseout=rollOffAll(); onclick="rollOffAll();return true;" href="http://www..html"><IMG border=0 name=mike alt=Mike src="../images/mikeoff.jpg" width=175 height=225></A> <BR><A onmouseover="swapImage('ON','boo');" onmouseout=rollOffAll(); onclick="rollOffAll();return true;" href="http://www..html"><IMG border=0 name=boo alt=Boo src="../images/boooff.jpg" width=175 height=225></A><BR> <BR><A onmouseover="swapImage('ON','randall');" onmouseout=rollOffAll(); onclick="rollOffAll();return true;" href="http://www..html"><IMG border=0 name=randall alt=Randall src="../images/randalloff.jpg" width=175 height=225></A><BR> </DIV> </BODY> </HTML> Similar TutorialsHi, I've investigated contacting the author, but it doesn't look like I'll get a swift response. The script I'm using is hosted here The script is designed to create a fullscreen, scaling background that can be used as a carousel gallery for images, with a caption that floats next to the mouse pointer that either reads 'next' or 'previous'. It works fine but I am attempting to alter the script to do a few things: 1.Make the image take up a proportionate amount of window space - 85% (done) 2.Get rid of the text which appears on rollover(done) 3.Assign an image flip for the proportionally scaled image (this is the one I'm having problems with) I'm trying not to include too much information but it's hard to know where the problem is. I'm fairly sure this is used to set the scaler up on the page: Code: (function(){ var bg=document.getElementById('bg'),float=document.createElement('span'),scale=Scaler(bg); //Create and bind scaler-function addEvent=function(el,on,fn){el.attachEvent?el.attachEvent('on'+on,fn):el.addEventListener(on,fn,false)}, //Function for cross-borwser addEvent move=function(e){ float.style.left=(e=e||window.event).clientX+20+'px'; float.style.top=e.clientY+20+'px'; if(float.nxt!=(e.clientX>(document.body.offsetWidth/2)))float.innerHTML=(float.nxt=!float.nxt)?'':''; //Change html only if needed }, swap=function(e){ var key=(e=e||window.event).type=='MouseOver'?(e.clientX>(document.body.clientWidth/2)?40:37):e.keyCode; if(key>36&&key<41){ var data=scale(key>38?'+1':'-1'),l=data.els.length; for(var i=0;i<l;i++)data.els[i].style.height=i==data.to?'85%':'0px'; } } I've then used a simple imageflip function and implemented it here Code: addEvent(bg,'mouseout',function('BNB_mouseon()'){float.style.display='none'}); //Hide floater when not over image addEvent(bg,'mouseover',function('BNB_mouseon()'){float.style.display='block'}); Where 'bg' stands for the background image div. I've been scratching my head about this for quite a while now, so any advice is appreciated! I'm attempting to impliment it on the website http://www.freddydewemathews.com/, for a little context How can I make a image where the first image "rolls" up and another (different) image "rolls" up from the bottom? I know how to code it except for the animation sequence. All images are 200 width and 50 height.\ Thanks in advance! (Would like to use jQuery if possible) ok I have this image and i want the image to change upon the mouse hovering over it. Which in it self is simple to do and I Google numerous different ways on how to do it. But each one i would be forced to use a <a href... in it. The thing is I don't want to use it cause i am already using HTML image map. I really need help on finding the code that would work... This is what I have Code: <html> <head> </head> <body> <p align="center"><img src="room.bmp" border="1" usemap="#maps" alt="Green room" /></p> <map name="maps"> <area shape="rect" coords="25,210,100,300" href="greenroom.html#energy" > <area shape="rect" coords="130,215,185,277" href="greenroom.html#water"> <area shape="rect" coords="80,11,263,149" href="greenroom.html#tv"> </map> ............. Hi, I'm having a problem getting one of my image rollovers to work, what confuses me is that the other image works fine, I'm trying to get this to work for an assignment here's the javascript: Code: rollImage = new Array() for(i = 0; i < 12; i++){ rollImage[i] = new Image(85,85); } rollImage[0].src = "images/narav2.jpg"; rollImage[1].src = "images/narav3.jpg"; rollImage[2].src = "images/sasuke-avatar-118.jpg"; rollImage[3].src = "images/sasuke.jpg"; function swapNar(img){ //this works fine document.nar11.src = rollImage[img].src; return true; } function returnNar(img){ //this function works fine as well document.nar11.src = rollImage[img].src; return true; } function swapSas(img){ //this function not working document.sasim.src = rollImage(img).src; return true; } function returnSas(img){ //this function also not working document.sasim.src = rollImage(img).src; return true; } Here's the HTML: Code: <tr> <td height="60"> <img src="images/narav2.jpg" name="nar11" width="85" height="85" border="0" id="nar11"/> </td> <td> <a href="naruto.html" onMouseover = "swapNar(1)" onMouseout = "returnNar(0)"> Naruto </a> </td> </tr> <!-- When I mouse over the above link the image rolls over as expected, the bottom link doesn't work as expected and I can't see what I'm doing wrong --> <tr> <td height="60"> <img src="images/sasuke-avatar-118.jpg" name="sasim" width="85" height="85" border="0" id="sasim"/> </td> <td> <a href="sasuke.html" onMouseout= "swapSas(3)" onMouseover= "returnSas(2)"> Sasuke </a> </td> </tr> I can't see what the problem is with the returnSas and swapSas functions, I'm still a noob at this and would really appreciate some assistance, thanks in advance Hi Guys, I'm wondering if anyone knows of some simple javascript that allows me to create a floating image rollover enlargement, similar to the ones on the homepage of ThemeForest. I've been Googling for hours, so, if anyone knows of a script, i'd be much appreciative. Thanks, Christian Hello, First of all, I am not a coder. I can put together some fairly simple HTML, and can borrow chunks of JS code to suit certain basic purposes. Also, I am terribly sorry if my technical lingo is way off target. I have managed to accomplish two separate goals using javascript, but am having trouble combining their results. I have created an image link that randomly calls a URL from an array. I also have a separate roll-over image. What I am trying to do is have the link that accesses the array also be a roll-over image. I can't seem to accomplish this. http://matrix.senecac.on.ca/~mlinhar...low/page7.html This URL is what I am working on. The "b" symbol is the roll-over. The "right" arrow accesses an array at: http://matrix.senecac.on.ca/~mlinhar...w/randomize.js I have tried simply adding my roll-over code to randomize.js and adjusting the array accordingly, but that doesn't seem to work. I would like the "right" arrow to be a roll-over image as the "b" symbol is, but also access the "randomize" array as it currently does. My problem is that my understanding of JS isn't great enough to determine how separate pieces of code might be combined or function together. Anyways, I'm sorry if my technical knowledge and abilities are too underdeveloped for this forum. I would appreciate any and all advice anyone might have. Hello. I want to display some text in some part of website when user "rolls over" an image. How can I make it possible? Text position must be totally flexible. (not over image) Hi friends, Im new with JS. How to make the roll over effect in JS. An image, on roll over, the big size of the same image needs to appear. regards anoop Can anyone show me the code for a simple expanding navigation bar? I need to roll over the nav bar and for it to drop down with more options. I know the code will be straight forward, I can't work it out though. Thanks whoever can help = ) Hi there, If anyone can help me it would be incredibly appreciated. I have this JavaScript file below. Currently it roll's over the image fine but the image stays as the hover after the mouse rolls over. Is there a really quick way to add a roll off/ mouse off function so the image rolls back to the underlying image? Again thank you in advance for any help you can provide for this problem as I'm very new to JavaScript! Chris *********** "// JavaScript Document $(function() { $('img[data-hover]').hover(function() { $(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover', $(this).attr('tmp')).removeAttr('tmp'); }).each(function() { $('<img />').attr('src', $(this).attr('data-hover')); });; }); *********** Could some one help me with achieving a roll over effect? Not the type where you hover over a link and a image appears and then you move away from the link and it disappears but rather like the ones viewable in the roll over section here @ www.dailyscience.com - that is you hover over a link and text and an image appears but then you move away and it still remains until you hover over another link? I'm a novice to javascript and am still learning so any help would really be appreciated, thanks! PS I realise there is a connection to the HTML code as this is where the content lies but interlinking this with my desired effect is rather annoying. Once again thanks. I want to mouse over a symbol (or coordinate) on an image and have a photograph appear of the real life item. Is there a code that could be used for doing this? Any help appreciated. Code: var rollnav = []; rollnav[0] = new Image ; rollnav[0].src ="buttons/button 1 suits.png"; rollnav[1] = new Image; rollnav[1].src = "buttons/button 2 suits.png"; rollnav[2] = new Image; rollnav[2].src ="buttons/button 1 dresses.png"; rollnav[3] = new Image; rollnav[3].src ="buttons/button 2 dresses.png"; rollnav[4] = new Image; rollnav[4].src ="buttons/button 1 christening.png"; rollnav[5] = new Image; rollnav[5].src ="buttons/button 2 christening"; rollnav[6] = new Image; rollnav[6].src ="buttons/button 1 Acessories.png"; rollnav[7] = new Image; rollnav[7].src ="buttons/button 2 Acessories.png"; rollnav[8] = new Image; rollnav[8].src ="buttons/button 1 home.png"; rollnav[9] = new Image; rollnav[9].src ="buttons/button 2 home.png"; rollnav[10] = new Image; rollnav[10].src ="buttons/button 1 contact us.png"; rollnav[11] = new Image; rollnav[11].src ="buttons/button 2 contact us.png"; rollnav[12] = new Image; rollnav[12].src ="buttons/button 1 links.png"; rollnav[13] = new Image; rollnav[13].src ="buttons/button 2 links.png"; function SwapOutsuit(){ document.suitnav.src = rollnav[1].src; return true; } function SwapBacksuit(){ document.suitnav.src = rollnav[0].src; return true; } function SwapOutdress(){ document.dressnav.src = rollnav[3].src; return true; } function SwapBackdress(){ document.dressnav.src = rollnav[2].src; return true; } function SwapOutchris(){ document.chrisnav.src = rollnav[5].src; return true; } function SwapBackchris(){ document.chrisnav.src = rollnav[4].src; return true; } function SwapOutaccess(){ document.accessnav.src = rollnav[7].src; return true; } function SwapBackaccess(){ document.accessnav.src = rollnav[6].src; return true; } function SwapOuthome(){ document.homenav.src = rollnav[9].src; return true; } function SwapBackhome(){ document.homenav.src = rollnav[8].src; return true; } function SwapOutcus(){ document.cusnav.src = rollnav[11].src; return true; } function SwapBackcus(){ document.cusnav.src = rollnav[10].src; return true; } function SwapOutlink(){ document.linknav.src = rollnav[13].src; return true; } function SwapBacklink(){ document.linknav.src = rollnav[12].src; return true; } hi im trying to create a series of rollover buttons for my site that can be used on all pages. im using the above array to switch the button images the problem is they all work up until number 9 then they just display the image set as the original image and dont change on mouse over. i try declaring an array with more than 9 spaces it doesn't seem to make a difference ive tried the new array format to with no avail. any help would be greatly appreciated. i have included my code which is embedded in my html to call the function below. Code: <A href="coolkids formal contact us.html" onMouseOver="SwapOutcus()" onMouseOut="SwapBackcus()"><img src="buttons/button 1 contact us.png" name="cusnav" align="left" ></A> <A href="information.html" onMouseOver="SwapOutlink()" onMouseOut="SwapBacklink()"><img src="buttons/button 1 links.png" name="linknav" align="left" ></A> Hi I use dreamweaver to build sites, and so don't really have to do much with the code, however adobe cs5 has removed the navigation bar tool and I am totally lost without it. I know Java script is needed... Could anyone help? If someone has some code ,for a vertical navigation bar with 8 buttons, 3 images for each button, buttonup mouse over and button down (which is of course a link to another page), that I could copy and edit, it would help alot! i have image button i need to display image .if the size of the image button is 100*100 and image size is 50*50 .the remaining space of the image button should be empty.the image should not stretch. can any one guide me i am new to programming Thanks in advance!!! I have gotten my script to do exactly what I want it to do with one exception. I have some thumbnail images that people can mouse over and the actual image is 100px by 75px. That is what I use for my thumbnail and they reside in www.website.com/images/thumbs/image1.jpg. I have the large version of the image that resides in www.website.com/images/image1.jpg. Its actual size is 640px by 480. When I mouse over my thumbnail, I don't want the thumbnail to appear for the larger image, I want the large image to appear instead? Let me know if you need ellaboration. Any help would be great! Thank you. Javascript Code: <script language="JavaScript"> function Change_Big_One(thumb){ document.getElementById('BigOne').src=thumb.src.replace("_th","") } </script> HTML THUMBNAIL Code: <div><img src="https://www.website.com/images/thumbs/image1.jpg" class="thumb" onMouseOver="Change_Big_One(this)"></div> HTML LARGER IMAGE Code: <div><img src="" id="BigOne"></div> QUESTION 1: Hello. I would like to know if this is possible with Javascript, and if yes, if someone can please provide me with the code or point me in the right direction. Let me start of by saying that this is for an eBay listing. I know that they accept basic / limited javascript and if what I am asking is possible, I hope that it can work on eBay listings. I would like to know if it's possible to determine the dimensions of an image with Javascript from an Image url, and to then resize it or not based on the the size of the image. So, let's say this is the URL: www.adomainname.com/image.jpg and let's say that image is 1400 px x 1400 px. I would first like the javascript code to detect that size. I also would like the maximum dimension for any side of the image to be 600 px. If both sides of the image are over 600 px, for both sides to be reduced proportionally to 600 px or lower. If any one side of the image is larger than 600 px, the image is to be resized to 600 px or lower. If both sides are under 600 px, the image is to not be reduced. It would also be nice if it can detect whether the image is portion or landscape based on I guess the larger side, because an image at 600 px in height might be too big, but in width might be o.k. So, in this example (the 1400 px by 1400 px), the image is to be resized to 600 px x 600 px. For an image that's 300 px x 500 px, it should remain as such. For an image that's 400 px x 700 px, it should be resized to 400 / (700 / 600) px by 600 px, which is approximately 343 px x 600 px. I have looked a bit into this and I see things being mentioned about the image being loaded first completely on the screen, or about using server side language like PHP, and so on, but like I said, keep in mind that this is for eBay, and so I am limited. Note: The part that I am most interested in is in being able to detect the size / dimensions of the image. QUESTION 2: On a side note, does anyone know if it's possible to have a Javascript enlarging function for images, in which when one clicks on an image, it is enlarged, but either in a popup window that's smaller than the one behind it, and possibly centered, or by making the background go dark and then bringing up the enlarged image (is the latter done with Javascript; I have seen this effect for a while now and have always wondered.) Hello, I am working on a page that has a jQuery full browser BG image and I am trying to also utilize a MooTools gallery. There seems to be some interference between the two JavaScripts as only one works (whichever one is last in order in the header of the HTML document). Links: http://www.courtneyhunt.com.au/press_bg.html http://www.courtneyhunt.com.au/press_gallery.html I am a complete novice with JavaScript so if anyone could help that would be great. Thank you in advance. Hi, I am still designing the website and want some flexibility. I am capturing the mouse clicks fine on top of an image, but the coordinates are absolute and not relative to the image. How can I capture mouse clicks relative to the image so that I can move the image anywhere in my website? Thanks! Here's what I usually use and have been using for years and it works great, just not for this particular purpose. I don't have a clue when it comes to javascript. Code: <noscript><img src="no_script_quote.gif" width="406" height="94"/></noscript><script language="javascript"> var delay=6000 var curindex=0 var images=new Array() images[0]="quote1.gif" images[1]="quote2.gif" images[2]="quote3.gif" images[3]="quote4.gif" images[4]="quote5.gif" var preload=new Array() for (n=0;n<images.length;n++) { preload[n]=new Image() preload[n].src=images[n] } document.write('<img name="defaultimage" src="'+images[Math.floor(Math.random()*(images.length))]+'">') function rotateimage() { if (curindex==(tempindex=Math.floor(Math.random()*(images.length)))){ curindex=curindex==0? 1 : curindex-1 } else curindex=tempindex document.images.defaultimage.src=images[curindex] } setInterval("rotateimage()",delay) </script> But, now I want to be able to set a default picture to be shown first and have the random pics appear next. I also don't want the default pic to show up again in the random array. So basically, every time the page was first visited, or refreshed it would show the default picture then move into the random pics. Is there anyway to modify the code that I'm using to accomplish this? Or... Any help would be appreciated. Thanks, Dell |