Hello!

I thought I share this little modification to image module to make the thumbnail image in the teaser to enlargen on mouseover or hover in other word. This modification based on css and not javascript!
I'm sure that there is better way to do this or if anyone would make a module out of it I would apprecaiate it but till then this is easy and it works. The actual effect and image locations can be changed if you change the css px values in section 3.:

1. I added an extra function to includes/common.inc:

function l2($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE, $html = FALSE) {
if ($path == $_GET['q']) {
if (isset($attributes['class'])) {
$attributes['class'] .= ' active';
}
else {
$attributes['class'] = 'active';
}
}
return check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html ? $text : check_plain($text)) ;
}

2. modify the following functions in modules/image/image.module:

function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {
// regenerate images?
if ($node->images[$label] != $node->images[IMAGE_ORIGINAL] &&
(!file_exists(file_create_path($node->images[$label])) ||
filemtime(file_create_path($node->images[$label])) < variable_get('image_updated', 0)))
{
_image_remove_derivatives($node);
_image_build_derivatives($node);
node_save($node);
drupal_set_message(t('The image %title had missing derivative image which has been regenerated.', array('%title' => $node->title)));
}

if (empty($node->images[$label])) {
return;
}

$image_info = image_get_info(file_create_path($node->images[$label]));
$attributes['class'] = "$label". (isset($attributes['class']) ? $attributes['class'] : "");
$attributes['width'] = $image_info['width'];
$attributes['height'] = $image_info['height'];

return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
}

function theme_image_teaser($node) {
return 'nid, array(), NULL, NULL, TRUE, TRUE).
image_display($node, IMAGE_ORIGINAL).'
';
}

3. Add the following to modules/system/default.css:

.content {

left: 0px;
position: relative;
top: 0px;

}

.content a .image image-_original {

display: block;
height: 0px;
left: -0px;
position: absolute;
top: -0px;
width: 0px;
}

.content a.image image-thumbnail , .content a.image image-thumbnail :visited {

display: block;

}

.content a.image image-thumbnail :hover .image image-_original {

display: block;
height: 200px;
left: 0px;
position: absolute;
top: 0px;
width: 200px;
}

.content {

left: 0px;
position: relative;
top: 0px;
width: 100px;
}

.content a ._original{

display: block;
height: 0px;
left: -0px;
position: absolute;
top: -0px;
width: 0px;
}

.content a.thumbnail, .content a.thumbnail:visited {

display: block;

}

----------------------------------------------------------
Have fun with! The modification code was base on the following demostration:
http://moneytreesystems.com/css/picpopup.html

.content a.thumbnail:hover ._original{

display: block;
height: 200px;
left: 0px;
position: absolute;
top: 0px;
width: 200px;
}

Keywords: thumbnail popup, mouseover thubnail, hover thumbnail, hover image, mouseover image, hover teaser, mouseover teaser, image module, mouse over, image effect, pop up image

Comments

vojnar’s picture

.content a.thumbnail, .content a.thumbnail:visited {

display: block;
height: 100px;
width: 100px;

}
Add width and hight so the the hover effect will be achived on the image area

vojnar’s picture

To make it work on IE:

1. add this to modules/system/default.css:

.content a.thumbnail:hover {
position: absolute;
}

2. Modify image.module image_display function to:

function image_display(&$node, $label = IMAGE_PREVIEW, $attributes = array()) {

// regenerate images?
if ($node->images[$label] != $node->images[IMAGE_ORIGINAL] &&
(!file_exists(file_create_path($node->images[$label])) ||
filemtime(file_create_path($node->images[$label])) < variable_get('image_updated', 0)))
{
_image_remove_derivatives($node);
_image_build_derivatives($node);
node_save($node);
drupal_set_message(t('The image %title had missing derivative image which has been regenerated.', array('%title' => $node->title)));
}

if (empty($node->images[$label])) {
return;
}

$image_info = image_get_info(file_create_path($node->images[$label]));
if($label=="_original")$label="original";
$attributes['class'] = "$label". (isset($attributes['class']) ? $attributes['class'] : "");
$attributes['width'] = $image_info['width'];
$attributes['height'] = $image_info['height'];
if($label=="original")$label="_original";
return theme('image_display', $node, $label, file_create_url($node->images[$label]), $attributes);
}

3. moules/system/default.css change "_original" to "original" in all classes:

.content a .original{

display: block;
height: 0px;
left: -0px;
position: absolute;
top: -0px;
width: 0px;
}

.content a.thumbnail:hover .original{

display: block;
height: 200px;
left: 0px;
position: absolute;
top: 0px;
width: 200px;
}

gurukripa’s picture

i saw a Drupal site www.ifood.tv where they have a similar effect to what u r saying...i wonder how they did it..

my intention is to have many images on the page..say a member list etc..and then make them grow large on mouseover..
was wondering the image gets loaded when the mouseover happens..

or its preloaded..in that case..it will increase the page load time a lot :(

Cld u paste the code once properly for Drupal 5.1 since i am not able to see it all..its in bits and pieces..and i am afraid..i might screw up :)

thanks

My internet voluntary services include

1. Helping answer queries on www.krishna.com
2. Learning & Helping in the Vedic section of www.spiritualnectar.com
3. Helped in some aspects to make www.indiapoised.org
4. Learning & ( Helping newbies) on www.drupal.org

bassplaya’s picture

I guess that's done with an iFrame.. it seems that the link of those members refers to their personal page..

Authentically,
BassPlaya

English Songs’s picture

Nice collection.. Its really hardwork...
I Specially Appriciate this Site Designer as well as OWNER of this site.........
Top 10 English Songs

zabalex’s picture

Cannot open your demo link (moneytreesystem...). Did you change the url? Please, repost.

Thank you,