功能介绍:打开zencart网站的时候,当鼠标放到一个产品图片上的时候显示该产品的另外一张图片,当鼠标移走的时候,显示为原始的图片。
实现原理:利用产品的细节图,鼠标移上去改变图片路径,路径变为细节图的第一张图。
优缺点对比如下:
优点:加强客户体验,网站丰富多彩。
缺点:不能与Image Handle融合实现缩略图功能(不用缩略图功能的可以无视)。
建议:产品图片不能太大,不然当鼠标放在产品图片的时候要1.5秒~2.5秒的时间图片才能切换。
演示效果预览:http://demo.tempvv.com/zonghe002/
修改步骤:
1,找到文件includes/functions/html_output.php ,搜索
-
function zen_image($src, $alt = '', $width = '', $height = '', $parameters = '') {
在上面一行添加代码:
-
function zen_image_info($src, $alt = '', $width = '', $height = '', $parameters = '') {
-
global $template_dir, $zco_notifier;
-
-
-
$alt = zen_clean_html($alt);
-
-
-
if (strstr($src, 'includes/templates') or strstr($src, 'includes/languages') or PROPORTIONAL_IMAGES_STATUS == '0') {
-
return zen_image_OLD($src, $alt, $width, $height, $parameters);
-
}
-
-
-
if ($src == DIR_WS_IMAGES and PRODUCTS_IMAGE_NO_IMAGE_STATUS == '1') {
-
$src = DIR_WS_IMAGES . PRODUCTS_IMAGE_NO_IMAGE;
-
}
-
-
if ( (emptyempty($src) || ($src == DIR_WS_IMAGES)) && (IMAGE_REQUIRED == 'false') ) {
-
return false;
-
}
-
-
-
if (!file_exists($src)) {
-
$src = str_replace(DIR_WS_TEMPLATES . $template_dir, DIR_WS_TEMPLATES . 'template_default', $src);
-
}
-
-
-
if (function_exists('handle_image')) {
-
$newimg = handle_image($src, $alt, $width, $height, $parameters);
-
list($src, $alt, $width, $height, $parameters) = $newimg;
-
$zco_notifier->notify('NOTIFY_HANDLE_IMAGE', array($newimg));
-
}
-
-
-
-
$width = emptyempty($width) ? $width : intval($width);
-
$height = emptyempty($height) ? $height : intval($height);
-
-
-
-
$image = '<img src="' . zen_output_string($src) . '" alt="' . zen_output_string($alt) . '"';
-
-
if (zen_not_null($alt)) {
-
$image .= ' title=" ' . zen_output_string($alt) . ' "';
-
}
-
-
if ( ((CONFIG_CALCULATE_IMAGE_SIZE == 'true') && (emptyempty($width) || emptyempty($height))) ) {
-
if ($image_size = @getimagesize($src)) {
-
if (emptyempty($width) && zen_not_null($height)) {
-
$ratio = $height / $image_size[1];
-
$width = $image_size[0] * $ratio;
-
} elseif (zen_not_null($width) && emptyempty($height)) {
-
$ratio = $width / $image_size[0];
-
$height = $image_size[1] * $ratio;
-
} elseif (emptyempty($width) && emptyempty($height)) {
-
$width = $image_size[0];
-
$height = $image_size[1];
-
}
-
} elseif (IMAGE_REQUIRED == 'false') {
-
return false;
-
}
-
}
-
-
-
if (zen_not_null($width) && zen_not_null($height) and file_exists($src)) {
-
-
-
$image_size = @getimagesize($src);
-
-
$ratio = ($image_size[0] != 0 ? $width / $image_size[0] : 1);
-
if ($image_size[1]*$ratio > $height) {
-
$ratio = $height / $image_size[1];
-
$width = $image_size[0] * $ratio;
-
} else {
-
$height = $image_size[1] * $ratio;
-
}
-
-
if ($image_size[0] < $width and $image_size[1] < $height) {
-
$image .= ' width="' . $image_size[0] . '" height="' . intval($image_size[1]) . '"';
-
} else {
-
$image .= ' width="' . round($width) . '" height="' . round($height) . '"';
-
}
-
} else {
-
-
if (IMAGE_REQUIRED == 'false') {
-
return false;
-
} else if (substr($src, 0, 4) != 'http') {
-
$image .= ' width="' . intval(SMALL_IMAGE_WIDTH) . '" height="' . intval(SMALL_IMAGE_HEIGHT) . '"';
-
}
-
}
-
-
-
if (defined('IMAGE_ROLLOVER_CLASS') && IMAGE_ROLLOVER_CLASS != '') {
-
$parameters .= (zen_not_null($parameters) ? ' ' : '') . 'class="rollover"';
-
}
-
-
if (zen_not_null($parameters)) $image .= ' ' . $parameters;
-
-
$image .= ' />';
-
-
return $image;
-
}
2,在函数zen_image区域内搜索
-
$image = '<img src="' . zen_output_string($src) . '" alt="' . zen_output_string($alt) . '"';
替换成:
-
-
if (!file_exists(str_ireplace('.jpg','_1.jpg',$src))){
-
$image = '<img src="' . zen_output_string($src) . '" alt="' . zen_output_string($alt) . '"';
-
}else{
-
$image = '<img src="' . zen_output_string($src) . '" onMouseOver="this.src='.'\''.str_ireplace('.jpg','_1.jpg',zen_output_string($src)).'\''.'" onMouseOut="this.src='.'\''.zen_output_string($src).'\''.'" alt="' . zen_output_string($alt) . '"';
-
}
-
3,找到文件includes/templates/你的模板/tpl_modules_main_product_image.php
搜索:zen_image($products_image_medium, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT)
替换成:zen_image_info($products_image_medium, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT)
4,修改完成了,去前台刷新一下看看效果吧。
注:步骤3是为了解决详细页面大图也切换图片,当然要改成不能切换的。