zoom icon indicating copy to clipboard operation
zoom copied to clipboard

multiple images

Open muszek opened this issue 13 years ago • 4 comments

It would be nice if we could have multiple images, like @ http://www.magictoolbox.com/magiczoom/integration/#multiple

muszek avatar Nov 16 '11 16:11 muszek

@muszek I have been working on something to use multiple images as well. My solution is to put the images into an array and then pull the index of the image and pass its source to the function when the thumbnail/image is clicked.

influxweb avatar Nov 17 '11 17:11 influxweb

I've come up with a work around for multiple images, basically cycle through each a tag, grab it's href for the large image then initialize the plugin like so:

$('a.zoom').each(function() {
     var url = $(this).attr('href');
     $(this).zoom({
          url: url
     });
});

dahliacreative avatar Apr 17 '13 10:04 dahliacreative

Another way which works well is to wrap the main return in a method on an object.

    // vars moved up to here
    var methods = {
        init: function(options){
            return this.each(function () {
                // rest of the code, drop the var though, but keep the variable assigning
                methods.url(settings.url);
            });
        },
        url: function(image_url){
            // img.onload function
            img.src = image_url
        }
    };

You can then change the image url externally from the plugin

    $('#my_zoom').zoom('url', 'new/url/to/image.ext')

Would need a bit more changing of the img.onload function as it currently will append the new image each time, but the idea behind it all works nicely

danjrichardson avatar May 08 '13 11:05 danjrichardson

Does this help anyone? I've created a pull request ( #55 ) that stops the appending of a new image if the plugin is called again. This way you can just pass the new url to the zoom plugin when you want to switch the image.

$(document).on('click', '.switch-image', function(){
  var newSrc = $(this).find('img')[0].src, mainImg = $('#mainImage img')[0];
  if(mainImg.src !== newSrc){
    mainImg.src = newSrc;
    $('#mainImage').zoom({ url: newSrc });
  }
});

stewartknapman avatar Jul 02 '14 21:07 stewartknapman