Jump to content

Recommended Posts

just found some scriped from google and it works well ;)

function actionWhenMouseOver(imgName) {    var img = document.getElementById(imgName);    img.style['width'] = "500px";    img.style['height'] = "500px";} function actionWhenMouseOut(imgName) {    var img = document.getElementById(imgName);    img.style['width'] = "200px";    img.style['height'] = "200px";}//and then for every image you want this to occur add the attribute:<image id="image1" src="" onmouseover="actionWhenMouseOver(this.id)" onmouseout="actionWhenMouseOut(this.id)"/>

but i must ask, how do i get the image to show its true size and not W=500 H=500 coz all images are diffrent shapes.

Link to post
Share on other sites

You MUST have a styling defining the width and height for the thumb nail image on page loading, otherwise it show as large on loading, and only show as a thumb nail when you hover over, and the mouse leaves the large image. You therefore need to set the size from width/height from 500px to "auto"

    img.style['width'] = "auto";    img.style['height'] = "auto";

But! you don't require JavaScript to achieve this, as it can all be done from using CSS only

<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script type="text/javascript">/*<![CDATA[*//*---->*/function actionWhenMouseOver(imgName) {    var img = document.getElementById(imgName);    img.style['width'] = "auto";    img.style['height'] = "auto";}function actionWhenMouseOut(imgName) {    var img = document.getElementById(imgName);    img.style['width'] = "200px";    img.style['height'] = "200px";}//and then for every image you want this to occur add the attribute:/*--*//*]]>*/</script><style type="text/css">/* for jvascript option */#image1 { width:200px; height: 200px;}/* all css option */#image_container img { width:200px; height: 200px;}#image_container img:hover{ width: auto; height: auto;}</style></head><body><image id="image1" src="../images/myimage.jpg" onmouseover="actionWhenMouseOver(this.id)" onmouseout="actionWhenMouseOut(this.id)"/><div id="image_container"><image src="../images/myimage.jpg" /></div></body></html>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...