Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple images #1

Open
muszek opened this issue Nov 16, 2011 · 4 comments
Open

multiple images #1

muszek opened this issue Nov 16, 2011 · 4 comments

Comments

@muszek
Copy link

muszek commented Nov 16, 2011

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

@influxweb
Copy link

@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.

@dahliacreative
Copy link

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
     });
});

@danjrichardson
Copy link

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

@stewartknapman
Copy link

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 });
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants