JavaScript - Moving Images To Different Div Tags (question)
I need to make it so that when a user moves the mouse over an image it appears enlarged in a seperate div tag when the user moves their mouse over the image
The problem is that the image just enlarges and makes a copy of itself in the div tag it is already in... this is the code: <td width="55" height="55"><div id="hello"><img src="jpegs for Thu/Copy of Misc/ajam.jpg" onmouseover="<div id = "Enlargedimage"><img src="jpegs for Thu/Copy of Misc/ajam.jpg"/> width="55" height="55"/></div></td> any help would be greatly appreciated Similar TutorialsI'm still kinda new at this. Please bear with me..I'm trying to make all imgs move in different directions using the following code. I was givin the code and I need to insert something into it so this will work. I just can't understand it and WANT to ..driving me NUTTY. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>BUZZ</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> var widthMax = 0; var heightMax = 0; var buzzSpeed = new Array(3); buzzSpeed[0] = 10; var xPosition = new Array(3); xPosition = -20; var yPosition = new Array(3); yPosition[0] = 0; var xDirection = new Array(3); xDirection[0] = "right"; var yDirection = new Array(3); yDirection[0] = "down"; function setBug(newStartPoint) { widthMax = document.documentElement.clientWidth; heightMax = document.documentElement.clientHeight; setInterval("flyBug(0)", 30); } function flyBug(curBug) { var activeBug = document.getElementById("bugImage" + curBug); var activeElement = document.getElementById("bugElement" + curBug); if (xDirection[curBug] == "right" && xPosition[curBug] > (widthMax - activeBug.width - buzzSpeed[curBug])) xDirection[curBug] = "left"; else if (xDirection[curBug] == "left" && xPosition[curBug] <= 0) xDirection[curBug] = "right"; if (yDirection[curBug] == "down" && yPosition[curBug] > (heightMax - activeBug.height - buzzSpeed[curBug])) yDirection[curBug] = "up"; else if (yDirection[curBug] == "up" && yPosition[curBug] <= 0) yDirection[curBug] = "down"; if (xDirection[curBug] == "right") xPosition[curBug] = xPosition[curBug] + buzzSpeed[curBug]; else if (xDirection[curBug] == "left") xPosition[curBug] = xPosition[curBug] - buzzSpeed[curBug]; else xPosition[curBug] = xPosition[curBug]; if (yDirection[curBug] == "down") yPosition[curBug] = yPosition[curBug] + buzzSpeed[curBug]; else if (yDirection[curBug] == "up") yPosition[curBug] = yPosition[curBug] - buzzSpeed[curBug]; else yPosition[curBug] = yPosition[curBug]; activeElement.style.left = xPosition[curBug] + document.documentElement.scrollLeft + "px"; activeElement.style.top = yPosition[curBug] + document.documentElement.scrollTop + "px"; } window.onresize = setBug; </script> </head> <body onload="setBug()"> <div id="bugElement0" style="position:absolute; left:20px; top:0px;"> <img id="bugImage0" src="bug.jpg" alt="buggy" height="48" width="48" /></div> <div id="bugElement1" style="position:absolute; left:25%; top:75%;"> <img id="bugImage1" src="bug.jpg" alt="buggy1" height="48" width="48" /></div> <div id="bugElement2" style="position:absolute; left:40%; top:48%;"> <img id="bugImage2" src="bug.jpg" alt="buggy2" height="48" width="48" /></div> <div id="bugElement3" style="position:absolute; left:58%; top:58%;"> <img id="bugImage3" src="bug.jpg" alt="buggy3" height="48" width="48" /></div> <div id="bugElement4" style="position:absolute; left:90%; top:75%;"> <img id="bugImage4" src="bug.jpg" alt="buggy4" height="48" width="48" /></div> </body> </html> So this is my first thread and I am a noob at javascript so please forgive obvious mistakes. I am try to make images float across the screen horizontally. Ideally I would like them to come from both sides and be at different y positions. The problem I am having is that I can only seem to get one to move at a time. Another problem is that when they move off to the right of the screen it expands the viewable size of the site. So here's what I've come up with thus far. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head> <title>Image Mover</title> <style> DIV.movable { position:absolute; } body { background-color: #0CF; } </style> <script language="javascript"> var x = 5; //Starting Location - left var y = 5; //Starting Location - top var dest_x = 1000; //Ending Location - left var dest_y = 5; //Ending Location - top var interval = 1; //Move 10px every initialization function moveImage() { //Keep on moving the image till the target is achieved if(x<dest_x) x = x + interval; if(y=dest_y) y = y + interval; //Move the image to the new location document.getElementById("cloud").style.top = y+'px'; document.getElementById("cloud").style.left = x+'px'; //if ((x+interval < dest_x) && (y+interval < dest_y)) { //Keep on calling this function every 100 microsecond // till the target location is reached window.setTimeout('moveImage()',100); } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body background="backgroundgradient.png" onload="moveImage()"> <div id="cloud" class="movable"> <img src="cloud01.png" /> </div> <script language="javascript"> var x = -100; //Starting Location - left var y = 5; //Starting Location - top var dest_x = 1500; //Ending Location - left var dest_y = 5; //Ending Location - top var interval = 1; //Move 10px every initialization function moveImage01() { //Keep on moving the image till the target is achieved if(x<dest_x) x = x + interval; if(y=dest_y) y = y + interval; //Move the image to the new location document.getElementById("plane").style.top = y+'px'; document.getElementById("plane").style.left = x+'px'; //if ((x+interval < dest_x) && (y+interval < dest_y)) { //Keep on calling this function every 100 microsecond // till the target location is reached window.setTimeout('moveImage01()',10); } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body background="web_layout/backgroundgradient.png" onload="moveImage01()"> <div id="plane" class="movable"> <img src="plane.png" /> </div> </body> </html> Any help is greatly appreciated. Thanks Code: function move_user_img(str) { var step = 25; // change this to different step value switch(str) { case "down": var x = document.getElementById('imageUser').offsetTop; x = x + step; document.getElementById('imageUser').style.top = x + "px"; break; case "up": var x = document.getElementById('imageUser').offsetTop; x = x - step; document.getElementById('imageUser').style.top = x + "px"; break; case "left": var y = document.getElementById('imageUser').offsetLeft; y = y - step; document.getElementById('imageUser').style.left = y + "px"; break; case "right": var y = document.getElementById('imageUser').offsetLeft; y = y + step; document.getElementById('imageUser').style.left = y + "px"; break; } } function move_report_img(str) { var step = 25; // change this to different step value switch(str) { case "down": var x = document.getElementById('imageReport').offsetTop; x = x + step; document.getElementById('imageReport').style.top = x + "px"; break; case "up": var x = document.getElementById('imageReport').offsetTop; x = x - step; document.getElementById('imageReport').style.top = x + "px"; break; case "left": var y = document.getElementById('imageReport').offsetLeft; y = y - step; document.getElementById('imageReport').style.left = y + "px"; break; case "right": var y = document.getElementById('imageReport').offsetLeft; y = y + step; document.getElementById('imageReport').style.left = y + "px"; break; } } Code: <div id ="display" style="width:640px; height:480px; overflow:hidden;"> <div> <img src =" <?php echo UPLOADPATH . $userImage; ?> " style = "position:absolute;" id="imageUser"/> </div> <div id ="imageReport"> <img src = " <?php echo $reportImage; ?> " style = "opacity:0.25;height:700px; width:450px;" /> </div> </div> <div style="position:absolute; top:550px; left:100px;"> <p>Control User Image</p> <input type=button onClick=move_user_img('up') value='Up'> <input type=button onClick=move_user_img('left') value='Left'> <input type=button onClick=move_user_img('right') value='right'> <input type=button onClick=move_user_img('down') value='down'> </div> <div style="position:absolute; top:650px; left:100px;"> <p>Control Report Image</p> <input type=button onClick=move_report_img('up') value='Up'> <input type=button onClick=move_report_img('left') value='Left'> <input type=button onClick=move_report_img('right') value='right'> <input type=button onClick=move_report_img('down') value='down'> </div> I have a javascript that loads images on the page based on the date you select from a drop down menu. So the images are displayed dynamically, however they are numbered 1 through 20. Is there a way I can add a title tag to the images that will display on mouseover? Here's the page I am working on. I want to add title tags to the six images on the right side of the page. They change based on the date selected. webpage Thanks. Is it just considered proper format to always have comment tags in javascript code such as */ and /* and // etc? thanks I'm trying to do some rollover images for a webpage I need to design, for class. I have them set up, and they work.. but the issue is that I set it up in such a way that the .js file is dynamic, and works for each page. You know, so that I don't actually have to specify the images within the .js file. The problem with THAT is that it doesn't automatically load the rollover version of each image, when the page loads.. so it's a bit sluggish. Here's my .js file Code: function swap_image(name,source) { document.images[name].src=source; var argv=swap_image.arguments; if(argv[2] && argv[3] && document.getElementById) { element=document.getElementById(argv[2]); element.innerHTML=argv[3]; } } Here's how I have it in the HTML Code: <a href="gallery" onmouseover="swap_image('gallery','/images/galleryro.jpg')" onmouseout="swap_image('gallery','/images/gallery.jpg')"> <img style = "top:150px; left:100px;" border="0" id="gallery" src="/images/gallery.jpg"/> </a> Is there anything I can do to force it to load the rollover image, without sacrificing my dynamic .js code? What is wrong with my code? I am trying to move a div and it wont work at all. Also my little <a> fix is really sloppy. Could I have some help with how I should fix that too? Thanks! Code: <html> <head> <script type="text/javascript"> var obj = document.getElementById("object"); var x = parseInt(obj.style.left); var y = parseInt(obj.style.top); function right(){ obj.style.left = "" + (x + 1) + ""; } function left(){ } </script> </head> <body> <a href="" onclick="right();"> <div id="container" style="position:absolute; top:100px; left:50%; margin-left:-400px; width:800px; height:600px; border:3px solid #808080;"> <div id="object" style="position:relative; top:559; left:379; background-color:#CCCCCC; width:40px; height:40px; border:1px solid #696969;"> </div> </div> </a> </body> </html> I already looked at this http://codingforums.com/showthread.p...ht=moving+text thread and I know it's similar. I just don't know what I am doing wrong. My css puts the text where it needs to go, then the script is supposed to alter it's pixel position and so it should move, right? Code: <html> <head> <style> item1 {position: absolute; left:20px; top:280px;} item2 {position: absolute; right:20px; top:280px;} </style> </head> <body> <item1 id="item1" >item1</item1> <item2 id="item2" >item2</item2> <script type="text/javascript"> var i=0; var j=0; var obj1=document.getElementById(item1); var obj2=document.getElementById(item2); obj1.style.visibility="visible"; obj2.style.visibility="visible"; //if (typeof obj1.style.left!="undefined" && obj2.style.right!="undefined") //{ //loop from ParseInt to coordinates in center of screen for (i=0;i<100;i++) { obj1.style.left=parseInt(obj.style.left) + i + "px"; document.write("<item1 id="item1">item1</item1>"); document.close(); } //for (j=0;j<100;j++) // { // obj2.style.right=parseInt(obj2.style.right) + j + "px"; // document.write("<item2 id="item2" >item2</item2>"); // } alert(i); //} </script> </body> </html> Am I anywhere close? I am trying this on IE6 (I only have Windows 2000) and on Firefox 3.5.3. Hello everyone. I am trying to make a flag with css and then move it with javascript. Code: <html> <head> <title>Flag</title> <link rel="stylesheet" type="text/css" href="flag3.css" /> <script language="javascript"> Hmove=-100; function moveObjRight(obj) { obj.style.left=Hmove; Hmove+=4; if(Hmove<900) window.setTimeout("moveObjRight(" +obj.id+ ");", 0); } </script> </head> <body> <h1>The flag of ___ by www</h1> <div id="bar3"> <div id="bar2"> <div id="bar1"> </div> <br /> <br /> <br /> <br /> </div> <br /> <br /> <br /> <br /> </div> <script language="JavaScript"> moveObjRight(bar3); </script> </body> </html> This is my code. The image is moving to the right, but i want it bounce from side-to-side in the browser window. Any help will be appreciated. Thank you. Hi, I'm noob , but i have nice idea i want to do it but i can't .. i tried many ways to do it .. but didn't work any of them .. the idea is move the foot to room no.1 .. but i want to see the foot moving on the red line to the room like this pic : Hello, I'm newbie in javascript, but i want to make an moving image. In time it should change to other image with other button. Also it could be changed by user. The change should be dynamic like moving from left to right. ^^ Any advices, tutorial links or smthing.. Thx I'm trying to create something like: http://www.deliciouslysortedibiza.com/ But I want the links to move like it does in there. Does anyone know the easiest way I could achieve this? Since I'm fairly new to Javascript and all. Thanks ! Hi there folks. I am a bit stuck with a little code. I am making a online yearbook entry and I wanted an image of myself animate/move from the top left hand to the bottom right of the screen. I also wanted to allow people reading it the option to change bg colour and text size - but I have managed to do those. The difficulty I am having is with moving the image, could anybody suggest any simple codes because I am new to this and don't want my head spinning before I go any further! Any help is greatly appreciated. Hey guys, I was trying to make a Javascript game that moves an image across the screen randomly. Instead of executing properly, it just shows the image's starting point, and stops. No movement. Is there anyway I could fix this? Thanks, Fizz. Code: <html> <head> <title>Image Mover</title> <style> DIV.movable { position:absolute; } </style> </head> <script language="javascript"> function Start() { var x = 5; //Starting Location - left var y = 5; //Starting Location - top var dest_x = Math.floor(Math.random()*650); //Ending Location - left var dest_y = 500; //Ending Location - top var interval = 10; //Move 10px every initialization moveImage(); } function NewDest() { var x = 5; //Starting Location - left var y = 5; //Starting Location - top var dest_x = Math.floor(Math.random()*650); //Ending Location - left var dest_y = 500; //Ending Location - top var interval = 10; //Move 10px every initialization moveImage(); } function moveImage() { //Keep on moving the image till the target is achieved if(x < dest_x) x = x + interval; if(y < dest_y) y = y + interval; //Move the image to the new location document.getElementById("ufo").style.top = y+'px'; document.getElementById("ufo").style.left = x+'px'; if ((x+interval < dest_x) && (y+interval < dest_y)) { //Keep on calling this function every 100 microsecond // till the target location is reached window.setTimeout('moveImage()',30); if (x == dest_x) && (y == dest_y) { NewDest(); } } } </script> <body onload="Start()"> <div id="ufo" class="movable"> <img src="Mouse.jpg" alt="mouse" WIDTH = 30/> </div> </body> </html> I have a blog with a two-column setup... a sidebar and a main section for posting articles, but encapsulated in a div wrap. I am creating a mobile site and want to: 1) remove/hide the sidebar 2) move the main section to the center for easy reading My issue is that I have tried CSS without success in accomplishing BOTH tasks. I easily can hide the sidebar using various methods, but the main section will not move to the center of the wrap, presumably because the sidebar is still there but not visible. So I went the JavaScript route instead with the following: Code: <script type="text/javascript"> <!-- if (screen.width <= 699) { var wrap = document.getElementById('wrap'); var sidebar = document.getElementById('sidebar'); wrap.removeChild(sidebar); wrap.style.background = "inherit"; } --> </script> Now my questions is... since the element is now removed, how do I move the main section to the center? I tried grabbing the main section with its id and floating it left (just to play around and see if it would move) and that didn't do anything. Any help would be appreciated. Hello ! I'm searching help regarding a script, function, or w/e that could enable me to move a DIV with acceleration & deceleration. Note: the DIV has a setTimeout on it to change sprites (I'm basically moving a little character) More details for what the script/function has to do - One function to start - It's accelerating from 1px/X to 5px/X (where X is in millisecond) in Y millisecond - One function to stop (which is obviously decelerating from 5px/X to a fixed position in Y millisecond (same as acceleration) Currently I have a stupid script whe First occurence of key pressing starts the move, and the continuous keypress occurence makes my object move 5px. I'm pretty sure it takes hugue amount of time for the browser to do it, so I'm trying to improve. My ideas: - Improve this method, obviously not a good solution in my opinion - Using a while loop that will trigger moving every Y millisecond (But that might kill the sprites's setTimeout) - Massive setTimeout every Y millisecond (Would that be good ?) - Using somehow a sleep() php-like function (It doesn't exist in JS ?) I hope I can improve my system quickly Thanks for helping, nico Hi Guys, seen some pages who give alerts or Warnings mentioning that i'm moving away from my webpage. Best example is hotmail when you are on the compose mail screen and when click another link it is asking for confirmation. Can you one please shed some light on how to do this. Your help is greatly appreciated. Cheers Dileep Hello. I am getting to learn JavaScript, and as for my first personal project, I would like to have a page with some text on it and when the user scrolls, a div containing a picture will move with the user when they scroll. I have found a solution, however, I do not like it. Code: <html> <head runat="server"> <title>Test</title> <link type="text/css" href="Main.css" rel="Stylesheet" /> </head> <body class="mainbackground"> <div id="group"> <div id="sizer" class="sizeholder"></div> <div id="image" class="image"></div> </div> <form id="form1" runat="server"> <div> <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /> </div> </form> <script type="text/javascript" > window.onload = function () { onscroll = function () { var scrollevel = document.body.scrollTop; if (scrollevel == 0) { if (window.pageYOffset) scrollevel = window.pageYOffset; else scrollevel = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0; } scrollevel = scrollevel + 250; document.getElementById("sizer").style.height = scrollevel + 'px'; } } </script> </body> </html> As you can see, it works by getting the scroll position and adding 250, to a height property-element above the image div. I have tried to use document.getElementById("image").style.top = scrollevel + 'px', but it does not work. Any ideas??? My code is: Code: <html> <head> <script type='text/javascript'> winx=220 winy=176 self.resizeTo(winx,winy); </script> <img id="default" style="z-index: 0;left: 0; position: absolute; top: 0px" height=32 width=32 align=baseline border=0 hspace=0 src='save.gif'></p> <script type="text/javascript"> document.getElementById("default".style.top = '0px'; document.getElementById("default".style.left = '0px'; </script> The image shows up, but it doesn't move. I can't seem to find out what I'm doing wrong. Edit: Finally spotted it, I was missing a ")" ._. |