Current location: Hot Scripts Forums » General Web Coding » JavaScript » Special rollover scripts


Special rollover scripts

Reply
  #1 (permalink)  
Old 05-26-04, 01:23 PM
alt-088 alt-088 is offline
New Member
 
Join Date: May 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Special rollover scripts

Hi Everyone -

I am looking for a javascript or IE function
that will enlarge the size of an image
when the mouse is rolled over and then
reduce it back to normal size after the mouse
leaves the image....

What i am looking for is a
lookalike to the macintosh action bar (or whatever it is called)

I know i can make the rollover image a different size than
the original normal image, but the table gets all out of whack
when i do a rollover...

anyone have any ideas??

thanks
tony
Reply With Quote
  #2 (permalink)  
Old 05-27-04, 10:44 PM
EvilHaider EvilHaider is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
I have seen this type of effect done with Flash but not with JavaScript. I'd be interested to see as well if someone can come up with a way to do this in JS.
__________________
**
Tutorial Maniacs
**
Reply With Quote
  #3 (permalink)  
Old 09-22-04, 07:17 AM
FunBundle FunBundle is offline
New Member
 
Join Date: Sep 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Special Rollover - example

Here is one possible solution out of many

This solution uses absolute positioning of the rollover image because absolute positioning places the element outside of the usual formatting rules, and so won't screw up your table design.

Make sure your table is fixed (so no surprises if browser window changes size)

Give your initial image an id, e.g.

<IMG ID="image1" SRC="whatever">

Anywhere inside the body create a hidden image with absolute positioning, e.g.

<DIV ID="image2" STYLE="position:absolute; visibility:hidden"><IMG SRC="rollover image"></DIV>

On the initial image onmouseover event, point to a JS routine to reposition the hidden, enlarged image to the exact same position as the initial image and then show the enlarged image. On the onmouseout or onblur event of the rollover image, hide the rollover image....

Complete, working example with cross-browser functionality is shown below. Hope this helped!

Code:
<html>
<head>
<title>Rollover Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="javascript">
<!--
// Global variables
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;

// Initialize upon load to let all browsers establish content objects
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
    }
}

// Seek nested NN4 layer from string name
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}
   
// Convert object name string or object reference
// into a valid element object reference
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        // pass through object reference
        theObj = obj;
    }
    return theObj;
}
   
// Convert object name string or object reference
// into a valid style (or NN4 layer) reference
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}
   
// Position an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
    var theObj = getObject(obj);
    if (theObj) {
        if (isCSS) {
            // equalize incorrect numeric value type
            var units = (typeof theObj.left == "string") ? "px" : 0;
            theObj.left = x + units;
            theObj.top = y + units;
        } else if (isNN4) {
            theObj.moveTo(x,y)
        }
    }
}

// read position of an element in regular document flow
function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}

// Set the visibility of an object to visible
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}
   
// Set the visibility of an object to hidden
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

//Show the rollover image
function ShowRollover()
{
    var position = getElementPosition("image1");
   // alert("X:"+x+" Y:"+y);
    shiftTo("rollover", position.left, position.top);
    show("rollover");
}
//-->
</SCRIPT>
</head>

<BODY BACKGROUND="layout_img/backmain.gif" onload="initDHTMLAPI()">
<CENTER>
    <TABLE WIDTH="600" border="1">
        <TR>
            <TD WIDTH="200">CELL 1</TD>
            <TD WIDTH="200"><IMG ID="image1" SRC="backup.gif" onmouseover="ShowRollover()"></TD>
            <TD WIDTH="200">CELL 3</TD>
        </TR>
    </TABLE>
</CENTER>
<DIV ID="rollover" STYLE="position:absolute; visibility:hidden">
    <img src="beige035.gif" onmouseout="hide('rollover')" onclick="alert('You clicked me!')">
</DIV>
</BODY>
</HTML>
Reply With Quote
  #4 (permalink)  
Old 09-22-04, 02:17 PM
bsilby bsilby is offline
Newbie Coder
 
Join Date: May 2004
Location: New Zealand
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,

The easiest way to produce the effect you want is to alter the width and height of the image on the rollover. Try this:

<html>
<head>
<title>Image Resize</title>
<script language="JavaScript">

function makeBig(img){
document.getElementById(img).style.width=10;
document.getElementById(img).style.height=10;
}

</script>

<body bgcolor="#FFFFFF" text="#000000">
<a href="javascript:;"onMouseOver="makeBig('Image1')" ><img src="testImage.gif" width="125" height="128" border="0" name="Image1"></a>
</body>
</html>

You'll need to write an size restore function to return the image to normal when the mouse moves away.

I hope this helps.

Cheers,
Brent.
__________________
BRENT SILBY
DEF-LOGIC
VIDEOGAMES
www.def-logic.com
Reply With Quote
  #5 (permalink)  
Old 10-17-05, 07:32 PM
iwnt2lrn iwnt2lrn is offline
New Member
 
Join Date: Oct 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Cant get it to work

I can't get the examples above to work with multiple images. Please help.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What are nullified scripts kaustubh Script Requests 14 03-30-05 06:18 AM
15.000+ scripts and no advanced search or sorting?!?! lee3001 General HotScripts Site Discussion 5 06-03-04 01:35 PM
Disappearing sponsored scripts BosDev HotScripts Site Bug Reports 3 01-22-04 05:43 PM
please sort scripts by updated date teletubby Hot Scripts Forum Questions, Suggestions and Feedback 11 08-17-03 12:23 PM


All times are GMT -5. The time now is 02:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.