简体   繁体   English

无法重新更改Javascript属性的值

[英]Unable to re-change the value of a Javascript attribute

I have two images which I'm toggling and a zoom on those images is supposed to be displayed according to the selected image. 我有两个要切换的图像,应该根据所选图像显示这些图像的缩放比例。 On the first page load everything works fine (image appears, zoom appears). 在首页加载时,一切正常(出现图像,出现缩放)。 After I click the image, the image swaps and the zoom works fine as well. 单击图像后,图像会交换,并且缩放效果也很好。 However, if I click again, I'm getting the image toggled correctly, but the zoom image does not refresh even for further clicks (keep displaying the zoom for the 2nd loaded image). 但是,如果再次单击,则会正确切换图像,但是即使再次单击,缩放图像也不会刷新(继续显示第二个加载图像的缩放)。 I'm trying to change the attributes of data-zoom-image but no luck. 我正在尝试更改data-zoom-image的属性,但是没有运气。 Any suggestions? 有什么建议么?

function pageLoad(sender, args) {
    zooming();
}
function chngimg(x) {

       if ($("#zoom_mw").attr("src") == x) {

           var rimage;
           rimage = $("#zoom_mw").attr('rearimage');

           $("#zoom_mw").attr("src", rimage);
           $("#zoom_mw").removeAttr("data-zoom-image");

           $("#zoom_mw").attr("data-zoom-image", rimage);
           $("#zoom_mw").elevateZoom({ scrollZoom: true });
       } else  {
           var fimage;
           fimage = $("#zoom_mw").attr('frontimage');
           $("#zoom_mw").attr("src", fimage);

           $("#zoom_mw").attr("data-zoom-image", fimage);

           $("#zoom_mw").elevateZoom({ scrollZoom: true });
       }
   }

<img style="border:1px solid #e8e8e6;" id="zoom_mw" 
onclick="chngimg('<%= Session("ImagePathFront")%>')"
frontimage='<%= Session("ImagePathFront")%>'
rearimage='<%= Session("ImagePathRear")%>'
    src='<%= Session("ImagePathFront")%>'   
    width="500" height="250"  />

I assume that you are using this library . 我假设您正在使用此库 Is this the case? 是这样吗

In my demo i copied your code and currently 我的演示中,我复制了您的代码 ,目前

  • it toggles the images. 它切换图像。
  • Your function pageLoad() calls a function zooming() but the code you provided does not execute pageLoad and the function zooming() is missing. 您的函数pageLoad()调用了函数zooming()但您提供的代码未执行pageLoad,并且缺少函数zooming()。
  • The call to elevateZoom is not working for me. elevateZoom的呼叫对我不起作用。 Are you missing a reference? 您是否缺少参考?

If you are using elevateZoom than you have to provide the URL for the larger Image 如果您使用elevateZoom ,则必须提供较大图像的URL

<img id="zoom_01" src="small/image1.png" data-zoom-image="large/image1.jpg"/>

Their exsample Gallery & Lightbox seems to me that it comes close what you are looking for: 在我看来,他们的样本画廊和灯箱似乎很接近您想要的东西:

<img id="img_01" src="small/image1.jpg" data-zoom-image="large/image1.jpg"/>

<div id="gal1">     
  <a href="#" data-image="small/image1.jpg" data-zoom-image="large/image1.jpg">
    <img id="img_01" src="thumb/image1.jpg" />
  </a>

  <a href="#" data-image="small/image2.jpg" data-zoom-image="large/image2.jpg">
    <img id="img_01" src="thumb/image2.jpg" />
  </a>        
</div>

And the matching javascript 和匹配的javascript

//initiate the plugin and pass the id of the div containing gallery images
$("#zoom_03").elevateZoom({gallery:'gallery_01', 
        cursor: 'pointer', galleryActiveClass: 'active'
        , imageCrossfade: true
        , loadingIcon: 'http://www.elevateweb.co.uk/spinner.gif'}); 

//pass the images to Fancybox
$("#zoom_03").bind("click", function(e) {  
  var ez =   $('#zoom_03').data('elevateZoom'); 
    $.fancybox(ez.getGalleryList());
  return false;
});

Please ask additional questions or comment if i misunderstood you. 如果我误解了您的意见,请提出其他问题或评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM