Topic: Random :Hover Backgrounds. (Page 1 of 1) |
|
---|---|
Maniac (V) Inmate From: Yes |
![]() I have a menu of 3 list items. inside each list item is a link. I have the hover property of the li set to show a random background image, however when I hover over the link inside of the li the background image changes again. I don't want this, in fact I would prefer if the whole li acted as the link. I tried making code like this: [code]li a { height: 100%; width: 100%} in the hopes that the link would then fill up the li but no luck. Here is the page. BTW only the first menu item uses the javascript code for random background images. I would much prefer to use PHP but the php script I've been using will pick a random image once and not reset it each time another hover is preformed. If you guys could help diagnoses this I would be very greatful, I'm willing to use totally different code but I would definetly like to avoid the javascript if at all possible. My css is http://www.milkstreetmedia.com/styles/main.css |
Paranoid (IV) Inmate From: Norway |
![]() Setting the width and height of the A has no effect if you leave them in display:inline; ( their default display type ). code: #navlist li a { display:block; background:url(images/paint/cssSprite.png) no-repeat 0px 1000px; } #navlist li a:hover { height:120px; /* height of the paint splashes */ } #navlist li.paint_0 a:hover { background-position:0px 0px; } #navlist li.paint_1 a:hover { background-position:0px -200px; /* 1x the width of the links/paint splashes */ } #navlist li.paint_2 a:hover { background-position:0px -400px; /* 2x the width of the links/paint splashes */ } #navlist li.paint_3 a:hover { background-position:0px -600px; /* 3x the width of the links/paint splashes */ } And add a random class ( paint_0 -> paint_N ) on the LI when you generate the markup of the page. The "bad" thing about this suggestion is that the A "grows" when hovered |
Maniac (V) Inmate From: Yes |
![]() Aww damn, I dunno why I didn't think of the background-position trick, i've used it before. Thanks! I got it working much better here: http://www.milkstreetmedia.com/two.html |
Paranoid (IV) Inmate From: Norway |
![]() Glad that helped. code: onload = function() { var navlist = document.getElementById('navlist'); if( !navlist ) return; navlist.onmouseout = function( event ) { var event = event||window.event; var src = event.target||event.srcElement; // go up until we find the LI or the UL while( src!=navlist && src.nodeName.toLowerCase()!='li' ) src = src.parentNode; // we hit the UL --> ciao if( src==navlist ) return true; // we hit a LI --> change className src.className = 'paint_'+ Math.round( Math.random()* 3 ); // stop propation of the event if possible if( event.stopPropagation ) event.stopPropagation(); return false; } } Of course that code could/should be beautified and made more generic and "standalone", but it works fine in IE7-8, Op9.5, Ff3 and Sf3 |
Maniac (V) Inmate From: Yes |
![]() I hate to admit it, but you're getting a lil' too advanced for me and I'm a bit lost |
Paranoid (IV) Inmate From: Norway |
![]() On your page, fixing the split second issue is just a matter of replacing onmouseover='...' by onmouseout='...' in the markup.
|