gpt4 book ai didi

jquery - jQZoom:remove()和img src更改后的innerzoom问题

转载 作者:行者123 更新时间:2023-12-01 04:57:35 24 4
gpt4 key购买 nike

我有一个 magento 在线商店,我正在尝试自定义产品页面。

在页面上,我有使用 jqZoom 的主产品图像,以及由 magento 生成的缩略图,以及可更改主图像的 onmouseover 功能。

经过长时间的更改功能和代码,今天我在 MacBook 上的两个浏览器中一切正常,但在我测试的任何其他计算机上都存在问题。

在第一次加载时,第一个图像加载完美,并且缩放工作正常,但是一旦您将鼠标悬停并且图像发生更改,缩放功能在大多数浏览器上就不再工作。

代码如下:

。。。。在头部我添加了这个:

<script>
$('imgzoom').ready(function(){
var options = {
zoomType: 'innerzoom',
title:false,
lens:false,
preloadImages: true,
alwaysOn:false,
zoomWidth: 300,
zoomHeight: 400,
xOffset:10,
yOffset:0,
position:'left'
//...MORE OPTIONS
};
jQuery('.imgzoom').jqzoom(options);
});
</script>


<script>
function startzoom() {
var options = {
zoomType: 'innerzoom',
title:false,
lens:false,
preloadImages: true,
alwaysOn:false,
zoomWidth: 300,
zoomHeight: 400,
xOffset:10,
yOffset:0,
position:'left'
//...MORE OPTIONS
};
jQuery('.imgzoom').jqzoom(options);
};
</script></code>

。。。。。这是magento 用于生成产品链接和大图像的代码

<p class="product-image product-image-zoom">
<?php
$_img = '<a href="'.$this->helper('catalog/image')->init($_product, 'image').'" class="imgzoom" rel="gal1" title="MYTITLE" id="imglink"><img width="380" name="img1" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" /></a>';
$imagehelper = $_helper->productAttribute($_product, $_img, 'image');
echo $imagehelper;
?>
</p>

。。。。。这是缩略图中进行所有更改的 foreach 循环

    <?php
++$i;
?>
<script>
function update_img<?php echo $i; ?>()
{
//$.jqzoom.disable('.jqzoom')
//jQuery('.imgzoom').disable('.imgzoom');
jQuery('.imgzoom').remove();
jQuery('.product-image.product-image-zoom').append('<?php echo $imagehelper; ?>');
img1.src = "<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()) ?>";
jQuery('#imglink').attr('href', '<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()) ?>');
startzoom();
//jQuery('#imgholdwrap').attr('style', 'width: 100%; height: 570px');
return false;

}
</script>
<a href="#" onclick="popWin('<?php echo $this->getGalleryUrl($_image) ?>', 'gallery', 'width=300,height=450,left=0,top=0,location=no,status=yes,scrollbars=yes,resizable=yes'); return false;" title="<?php echo $this->htmlEscape($_image->getLabel()) ?>"><img onmouseover="update_img<?php echo $i; ?>()" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()); ?>" width="66" height="100" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /></a>

。。。.

我认为主要问题是在删除 jQzoom 并将其添加回来之间的某个位置,图片的高度传输不正确,因此调用了该函数,但 jqZoom 生成的 & 具有高度0,如果您将代码检查器中的设置更改为某个 px 值,缩放将起作用,但图片未正确剪切

以下是网站上产品的链接: http://zeroinchapparel.com/index.php/men-short-sleeve/grand-experience.html

附:最终我需要将缩放图片显示为标准(在图片右侧),但是,当我将设置设置为标准时,带有缩放图片的窗口没有显示,z-index 是否存在一些问题?

附注2。这是我第一次使用 javascript 或 jQuery,所以我完全是个菜鸟!

更新:发现一些与IE不兼容的代码,很容易替换

 img1.src =  "<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()) ?>";

结果发现 IE 无法将新的 src 分配给 id“IMG1”,将其重写为:

document.getElementById('img1').src =  "<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()) ?>";

某些版本的 Chrome 仍然存在问题,在 src 更改后鼠标悬停时不会显示缩放图像...

最佳答案

我使用了以下内容:

jQuery(document).ready(function(){
// activate on mouseover since IE8/9 don't seem to fire it automatically.
jQuery(".product-image").on('mouseover',function(){
jQuery(".jqzoom").jqzoom(options);
})
});

连同:

jQuery(document).ready(function(){
jQuery(".thumbnail").click(function(){
var smallUrl = jQuery(this).attr('data-img-small');
var bigUrl = jQuery(this).attr('data-img-big');
// Remove the old/default image.
jQuery(".jqzoom").remove();
// Add the desired images back in from the thumbnails
jQuery(".pad-image").append('<a href="'+bigUrl+'" class="jqzoom"><img src="'+smallUrl+'"/></a>');
// Turn it off, wait for next `mouseover`.
jQuery(".jqzoom").off();
});
})

这似乎在其他浏览器上运行得很好。

我将 data-img-smalldata-img-big 属性设置为缩略图,使用 display: none; 其中需要,而且我还没有真正看到任何不良行为。

关于jquery - jQZoom:remove()和img src更改后的innerzoom问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13372147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com