JavaScript - On Hover Load Image
Hi all
I have a list of items that when you hover over them it displays an image (using CSS). This is fine when the list is small but when the list is large it takes a while to load all the images... this then delays any javascript on the page from running until all the images are loaded. Is there a way to either: * Use javascript to make it so the image only loads when the link is hovered over? or * Allow the rest of the javascript on the page to run before the images are finished loading? I think i'd prefer the first solution if possible but i'm open to all ideas. Thanks in advance! Similar TutorialsHello all. I'm sure this is really easy, but I have a question about being able to change a main image depending on a mouseover of particular text. I have a website where I am hosting a recipe, and I want to be able to show a 'main' picture that changes depending on where the user is hovering in the instructions. It would be very similar to this: http://piscesmike.com/Pages/recipes/onions.html The exception being that the top images are replaced by line by line instructions, and the main image changes depending on which instruction you are hovering on. Alternatively, I could also use a pop-up window with the image for the particular instruction, but could not get that to work either. I coded everything for the above link, but just cant seem to get this working. Any help is greatly appreciated. And, also feel free to try out the recipe's from PiscesMike.com, or to poke around. I know there are a few other errors (one being the day of the week deal) so once again, any input or help would be a tremendous help. Thanks and sorry for being such a noob! Instead of loading the data when the page loads (thus making the page load slower) I wanna make it load when you hover over the tool tip so how would I change this? PHP Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <title>Test Screenname</title> <style type="text/css"> body {color:#000;background-color:#FFF; font-family:Arial, Helvetica, sans-serif;} /*tooltip*/ div.tooltip { width: 200px; color: #fff; text-align: center; } div.tooltip h4 { color: #fff; font-weight: bold; text-shadow: 2px 2px 1px #222; margin: 0; padding: 13px 10px 5px; background: url(img/balloon.png) top left no-repeat !important; background: url(img/balloon.gif) top left no-repeat; font-size: 11px; } div.tooltip p { margin: 0; padding: 0 10px 15px; text-shadow: 2px 2px 1px #222; background: url(img/balloon.png) bottom left no-repeat !important; background: url(img/balloon.gif) bottom left no-repeat; font-size: 10px; } </style> <script type="text/javascript" src="mootools.js"></script> <script type="text/javascript"> window.onload=function() { /* setup tooltips */ var as = []; $S('a').each(function(a){ if (a.getAttribute('title')) as.push(a); }); new Tips(as, {maxOpacity: 0.9, maxTitleChars: 25}); } </script> </head> <body> <a href="#" title=" <?php $url = "http://www.blockstatus.com/aim/status-checker/index.php"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,"aimac=screenname"); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); $result2 = curl_exec ($ch); curl_close ($ch); $data = $result2; $pattern = '/Status:<\/b>(.*?)<br.*?><\/td>/i'; preg_match($pattern, $data, $status); $output = str_replace("Status: ", "", $status[1]); $aimstatus = trim($output); echo "$aimstatus"; ?> ">Test tooltip</a> </body> </html> Hello. I'm trying to improve page loads times on my site and I've tracked the issue down to the share buttons we have. We load the Tweet Button, Facebook Like Button, and Google +1 button sometimes up to 25 times on one page. What I'd like to do is, on initial load, display an image that looks like the Tweet Button, for example, and then when hovering over a div, change to the actual Tweet Button code. I know how to do this in general, but the key is that the actual tweet button code doesn't load when the page loads, only when you hover over the div does the actual code load. Can someone please give me a general template and I can integrate it in with my site? Thanks. Hi I'm an AS3 dev learning Javascript. I'm currently writing a simple script that loads an image as seen below. I deliberately misspell the file name to test the fail. Code: var fileName = "anImageThatDoesntExist.jpg"; var image = new Image(); image.onload = imageLoaded; try { image.src = "images/" + fileName; } catch( error ) { console.log('load error', error.message ); } finally { console.log('unable to catch error!') } function imageLoaded( event ) { console.log('image loaded'); } When I run this script I was expecting the 'catch' to pick up the error and tell me that the file doesn't exist. The 'catch' statement is ignored and 'finally' is executed. I would be very grateful if someone could let me know if I'm writing the try/catch incorrectly or whether it doesn't work in this way when loading an image. Many thanks in advance.... Hello everyone, I'm looking for a javascript script that will load a small image where the mouse is, then it would go away after a couple seconds. Thanks a bunch! Hi I have created the following page http://kylehouston.com/new/choir_contact.html I have added JQuery to smoothly fade in the screenshot on this page but on the first load the image gradually loads which misses out on the fade in effect. Is there a way I can load the image invisibly and then fade it in? Thanks in advance for your advice Kyle Hello, I was wondering if anyone could help me with a personal website I am modifying for a friend. He basically has a list of links such as: Home Blog Pictures Links What I want to do is that whenever you roll over, say, "Blog", an image appears to the right of the links (the image will be a small screenshot of what the blog looks like). When you roll over "Pictures", a different image appears in it's place. I already know how to do this when rolling over images, but not rolling over text. I used document.getElementById and just set the src to the image, but how do I do this when I just have text to roll over? Is it possible/recommended to use the follow JQuery? http://ajax.googleapis.com/ajax/libs.../jquery.min.js Thank you for your time On my website http://smstext.jigowatt.co.uk i have a menu which when you hover over certain parts popups with information. I have designed a Mooflow document that I want to popup instead (i will design a different one for each section). I cant get it to show up when you hover? I am trying to add a php link in the javascript file that links the hover images. This is my code at the moment Code: var ddimgtooltip={ tiparray:function(){ var tooltips=[] //define each tooltip below: tooltip[inc]=['path_to_image', 'optional desc', optional_CSS_object] //For desc parameter, backslash any special characters inside your text such as apotrophes ('). Example: "I\'m the king of the world" //For CSS object, follow the syntax: {property1:"cssvalue1", property2:"cssvalue2", etc} tooltips[0]=["http://i1189.photobucket.com/albums/z423/creativeedge1/Golf-Popup1.gif", "", {background:"#FFFFFF", color:"black", border:"2px ridge #0099FF"}] tooltips[1]=["http://i1189.photobucket.com/albums/z423/creativeedge1/hospitals_popup_copy.gif", "", {background:"#FFFFFF", color:"black", border:"2px ridge #0099FF"}] tooltips[2]=["../dynamicindex14/winter.jpg"] tooltips[3]=["../dynamicindex17/bridge.gif", "Bridge to somewhere.", {background:"white", font:"bold 12px Arial"}] return tooltips //do not remove/change this line }(), tooltipoffsets: [20, -30], //additional x and y offset from mouse cursor for tooltips When I am trying to link the php I use this code Code: var ddimgtooltip={ tiparray:function(){ var tooltips=[] //define each tooltip below: tooltip[inc]=['path_to_image', 'optional desc', optional_CSS_object] //For desc parameter, backslash any special characters inside your text such as apotrophes ('). Example: "I\'m the king of the world" //For CSS object, follow the syntax: {property1:"cssvalue1", property2:"cssvalue2", etc} tooltips[0]=[<link href="<?php bloginfo('template_directory'); ?>/index2.php", "", {background:"#FFFFFF", color:"black", border:"2px ridge #0099FF"}] tooltips[1]=["http://i1189.photobucket.com/albums/z423/creativeedge1/hospitals_popup_copy.gif", "", {background:"#FFFFFF", color:"black", border:"2px ridge #0099FF"}] tooltips[2]=["../dynamicindex14/winter.jpg"] tooltips[3]=["../dynamicindex17/bridge.gif", "Bridge to somewhere.", {background:"white", font:"bold 12px Arial"}] return tooltips //do not remove/change this line }(), tooltipoffsets: [20, -30], //additional x and y offset from mouse cursor for tooltips Obviously I am doing something wrong but I'm not sure what!?? Help Please Right i need some help with some code, i have been trying 2 days to get it to work! basically the 3 image locations are in Variables in PHP $piclocation1 $piclocation2 $piclocation3 What i want is when you hover over the div class "breaking-news", i want the div ID "latest-news-image" to change to that specific image background. example the top "breaking-news" class is on hover and the image $piclocation1 should show in "latest-news-image". if the middle "breaking-news" class is on hover the image $piclocation2 should show in "latest-news-image". and so on if you could help me figure out a way around to get this to work i would be ever so greatfull, as i dont know if i got this in the right area as it would contain javascript, php and poss Css! and even if you could point me in the right direction would be helpful! this is the website page i am testing it on if you would like to look at if visually http://www.wolverhampton-wanderers.co.uk/text.php and here is the code: Code: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="Stylesheet" type="text/css" href="./wolves.css"/> <title>Untitled Document</title> <?php $getnews = "SELECT * FROM `news` ORDER BY `news`.`id` DESC LIMIT 3"; $news = mysql_query($getnews) or die(mysql_error()); $counter = 1; while($row1 = mysql_fetch_array($news)){ if($counter == 1) { $picture1 = $row1['imageID']; $getimage1 = "SELECT * FROM news_images WHERE imageID = $picture1"; $image1 = mysql_query($getimage1) or die(mysql_error()); $pic1 = mysql_fetch_array($image1); $piclocation1 = $pic1['imageFile']; } if($counter == 2) { $picture2 = $row1['imageID']; $getimage2 = "SELECT * FROM news_images WHERE imageID = $picture2"; $image2 = mysql_query($getimage2) or die(mysql_error()); $pic2 = mysql_fetch_array($image2); $piclocation2 = $pic2['imageFile']; } if($counter == 3) { $picture3 = $row1['imageID']; $getimage3 = "SELECT * FROM news_images WHERE imageID = $picture3"; $image3 = mysql_query($getimage3) or die(mysql_error()); $pic3 = mysql_fetch_array($image3); $piclocation3 = $pic3['imageFile']; } $counter = $counter + 1; } ?> </head> <body> <div class="shaddow"><!-- This is the shaddow behind the content --> <div class="content"> <!-- This is the content and main background --> <div class="header"><img src="../images/header.jpg"/></div> <div class="menu"> <div id="nav"> <?php $cat = "SELECT * FROM `top-menu` ORDER BY 'category' ASC"; $category = mysql_query($cat) or die(mysql_error()); $start = 1; while($row = mysql_fetch_array($category)){ $submenu = $row['sub-menu']; if($submenu == '1'){ echo "</li><li><a id='{$row['Active-ID']}' " . "href='{$row['Address']}'>" . "{$row['Text']}</a>"; } elseif($submenu == '2'){ if($start == 1){ echo "<ul>"; } echo "<li><a id='{$row['Active-ID']}' " . "href='{$row['Address']}'>" . "{$row['Text']}</a></li>"; $start = $start + 1; if($submenu !='2'){ echo "</ul></li>"; $start = 1; } } } echo "</ul></li><a class='nav-end'></a>"; ?> </div> </div> <div id="latest-news"> <?php $getnews = "SELECT * FROM `news` ORDER BY `news`.`id` DESC LIMIT 3"; $news = mysql_query($getnews) or die(mysql_error()); $counter = 0; echo "<div id='latest-news-image'></div>" . "<div id='latest-news-header'>Breaking News</div>"; while($row1 = mysql_fetch_array($news)){ echo "<div class='breaking-news'><div class='breaking-news-header'><a href='#'>{$row1['title']}</a></div>" . "<div class='breaking-news-info'>Posted on {$row1['date']}, by {$row1['author']}</div>" . "<div class='breaking-news-desc'>{$row1['desc']}</div>" . "<div class='breaking-news-readmore'><a href='#'>Read More</a></div></div>"; $counter = $counter + 1; } ?> </div> </div> </div> </body> </html> 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 am looking to enlarge an image when its hovered over, can anyone give me the code for this? Thanks Ok. Basically, I will have images, about 150x100 that are all different. They will be displayed on a page in groups of 4. I want to make it so that if you hover over them, another image of the same size is put on top of that with part alpha. To give you an idea of what I am doing, it will be like youtube videos when you hover over them except I want there to be an image centered. I know this part of the code, but I don't know what to put inside it: Code: $(document).ready(function(){ $("img").mouseenter(function(){ //add image on top of this image }) $("img").mouseleave(function(){ //remove covering image }) }) What should I replace the comments with? Thanks Hey, I want javascript to change the background image on hover. This is my javascript: Code: function navOver(obj){ var imgUrl = 'url(images/' + obj.id + '.hover.png) center no-repeat'; obj.style.background='imgUrl'; } function navOut(obj){ var imgUrl = 'url(images/' + obj.id + '.png) center no-repeat'; obj.style.background='imgUrl'; } and this is the HTML: Code: <li id="home" onmouseover="navOver(this)" onmouseout="navOut(this)"></li> This doesn't work, can anyone help me and say me what to do? Dear all, I have been trying to replicate a cool javascript effect that appears here. See the funky images fading in when hovering with mouse? I want that ;-) By using Firebug I think I have narrowed down the code needed to: Code: <div id="main" class="clearafter"> <div class="inner clearafter"> <div class="columns clearafter"> <div class="project hovers column" style="border-color: rgb(255, 255, 255); cursor: pointer; background-color: rgb(255, 255, 255);"> <a href="http://mountfolly.co.uk" class="image"> <img width="274" height="137" alt="project" src="/images/41_project.jpg" class="screenshot"> <img width="274" height="137" alt="project" src="/images/7_project.jpg" class="text" style="opacity: 0; display: inline;"> </a> <h3>Text and titles etc...</h3> <p>etc etc etc...</p> </div> <div style="border-color: rgb(255, 255, 255); cursor: pointer; background-color: rgb(255, 255, 255);" class="project hovers column"></div> </div> </div> </div> <script type="text/javascript" src="/javascript/global.js"></script> and this (which I put into a javascript file called global.js): Code: /* project listings */ // to deal with IEs opacity idiocy $(function() { $('.project.hovers .text').css({opacity: 0}).show(); $('.project.hovers').css({cursor: 'pointer'}).click(function() { location.href = $('h3 > a', this).attr('href'); }); }); $('.project.hovers').hover( function () { $('.text',this).stop().fadeTo('100',1); $(this).stop().animate({borderTopColor: '#E9E9E9', borderRightColor: '#E9E9E9', borderBottomColor: '#E9E9E9', borderLeftColor: '#E9E9E9', backgroundColor: '#EEE' }, 100) }, function () { $('.text',this).stop().fadeTo(1000,0); $(this).stop().animate({borderTopColor: '#FFF', borderRightColor: '#FFF', borderBottomColor: '#FFF', borderLeftColor: '#FFF', backgroundColor: '#FFF' }, 1000) } ); But when I re-create the files (index.html, global.js, and replacement images) all I get is this. No hover effect... Any ideas what is missing? Would appreciate some help. Thanks, Wysiwyger PS: If you fancy a laugh, check these out I used DrDOS's solution from http://www.codingforums.com/showpost...17&postcount=8 and modyfied it a bit so I have 2 images, first without and 2nd with a link to other page. It works just fine in FF but in Chrome and in IE it shows just 2nd image. On place where first image shall be it's just blank white space. I have javascript enabled in all browsers, btw. Here's a code in head: Code: <script type="text/javascript"> function loadImg() { document.getElementById("loadimg").innerHTML="<img src=\"logo2.png\""; } function loadImg2() { document.getElementById("loadimg2").innerHTML="<a href=\"http://site.com\"><img src=\"logo2.png\"</a>"; } </script> And here's body part: Code: <div class="bottleft"> <div id="loadimg"></div> <script type="text/javascript">var myimg = setTimeout("loadImg();",5000);</script> </div> <div class="bottright"> <div id="loadimg2"></div> <script type="text/javascript">var myimg = setTimeout("loadImg2();",5000);</script> </div> I'm trying to figure out this whole day but just can't see where I am making a mistake? How can I make it to where an image will load in the corner of a website? Specifically, I have part of a template I want all people to see, however, some people either get it cut off or not shown at all because of their resolution. It must be a simple thing... I am trying to change an image source on page load depending on the contents of a cookie: Code: function goVisited(cookiename,img_name,img_src) { var visited = readCookie(cookiename); if (visited == "1"){ //alert("visited!"); document[img_name].src=img_src; }} <img onload="goVisited('main1','Introduction','img/Yellow.gif');" name="Introduction" border="0" src="img/Green.gif" width="250" height="18"> I need the page to check the cookie "main1" and if its value is 1, then change the image src from Green.gif to Yellow.gif. It almost works, but I get a stack overflow. Basically I want an effect like this: http://www.appelsiini.net/projects/l...ed_fadein.html Where the images on the page fade in as the user scrolls down. I implemented the code on a page, he http://www.jamiewebster.co.uk/orca.html Now, I have a couple of issues with this. First issue, it works in FF but it doesn't seem to work in Chrome. Second issue, I can see the alt text of the images below just above the fold of the page before the image loads (I guess it depends on your monitor size on wether you'll see it or not, but its still a problem!) Thirdly, it seems that once the images have loaded, if you scroll back up you no longer have the fade effect and it only happens once (unless you refresh the page) - would be good if that effect could happen every time you scroll. Any ideas, or if there is better code out there? Thanks in advance!! Hello, Can anyone figure out whats going on with this page and i need to finish the site by this evening? It is a wordpress site. the background image is shifting to the right on IE7 after the page loads on only the homepage. I think its the slider but im not sure www.grapevineoutreach.org thanks |