【问题标题】:show another image on mouse over of the default image in category product list in magento在magento的类别产品列表中的默认图像上显示另一张图像
【发布时间】:2013-02-16 12:35:24
【问题描述】:

我正在开发一个 magento 网站。在我的类别产品列表页面 (catalog/products/list.phtml)。我需要在默认图像上的鼠标上实现交换图像功能...(这里每个产品都有 2 个或更多图像,当鼠标悬停在默认图像上时,应该显示任何其他图像)

我是这个 magento 的新手..

有没有人帮助我..

【问题讨论】:

    标签: php jquery magento


    【解决方案1】:

    据我所知,magento 默认情况下仅在类别页面上加载 1 张图片,即“small_image”。 如果要显示任何其他图像,则必须创建产品的完整实例

    $_product = Mage::getModel('catalog/product')->load([product id]);
    

    然后循环浏览媒体库:

    foreach ($_product->getMediaGalleryImages() as $image) {
      // assign the image you want to the product object
      $_product->setImage($image->getFile());
    } 
    

    完成后,您可以使用

    访问新图像
    echo $this->helper('catalog/image')->init($_product, 'image')->resize(200, 350); 
    

    上面将返回200x350的图片缓存版本的图片url
    将此分配给图像的数据属性并使用 javascript 在鼠标悬停时更改 img src
    您可能需要考虑使用 javascript 预加载所有这些鼠标悬停图像,以便为用户提供最佳体验

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多