Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions css/easyzoom.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@
background: #FFF;
}

.easyzoom-lens {
position: absolute;
top: 0;
left: 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top and left properties can be removed as they're specified in the JS anyway

background-color: #FFF;
background-color: rgba(255, 255, 255, 0.35);
border: 1px solid #CCC;
border-color: rgba(0, 0, 0, 0.35);
width: auto;
height: auto;
cursor: pointer;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should maintain the crosshair cursor, I think the pointer gives the wrong signals - IE. you can click when you can't.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually had been pondering that, however, I ended up needing to be able to click through the lens so as to open a modal, which I was able to accomplish in the onShow function. I wasn't sure whether the cursor should be pointer, remain crosshair, or be invisible when using the lens overlay. Maybe that particular feature shouldn't be included in the plugin itself. Thoughts?

How I used onShow:

onShow: function(){
    if(this.opts.showLens){
        $(this.$lens).on('click', {'link': this.$link}, function(ev){
            ev.data.link.trigger('click');
        });
    }
}

-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about the prefixes these days http://caniuse.com/#search=box-sizing

}

/**
* EasyZoom layout variations
*/
Expand Down
41 changes: 40 additions & 1 deletion src/easyzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict';

var dw, dh, rw, rh, lx, ly;
var dw, dh, rw, rh, lx, ly, lw, lh;

var defaults = {

Expand All @@ -18,6 +18,9 @@
// Prevent clicks on the zoom image link.
preventClicks: true,

// Show zoom lens over target image.
showLens: false,

// Callback function to execute when the flyout is displayed.
onShow: $.noop,

Expand Down Expand Up @@ -52,6 +55,7 @@

this.$flyout = $('<div class="easyzoom-flyout" />');
this.$notice = $('<div class="easyzoom-notice" />');
this.$lens = $('<div class="easyzoom-lens" />');

this.$target.on({
'mousemove.easyzoom touchmove.easyzoom': $.proxy(this._onMove, this),
Expand Down Expand Up @@ -95,6 +99,16 @@
rw = dw / w1;
rh = dh / h1;

if(this.opts.showLens){
lw = Math.ceil(w1 * (w2 / this.$zoom.width()));
lh = Math.ceil(h1 * (h2 / this.$zoom.height()));
this.$lens.css({
width: lw,
height: lh
});
this.$target.append(this.$lens);
}

this.isOpen = true;

this.opts.onShow.call(this);
Expand Down Expand Up @@ -223,6 +237,29 @@
var top = xt * -1;
var left = xl * -1;

if(this.opts.showLens){
var th = this.$target.height();
var tw = this.$target.width();

var lt = Math.max(0, pt - (lh / 2));
var ll = Math.max(0, pl - (lw / 2));

if(pt + (lh / 2) - th > 0){
lt = th - lh;
}
if(pl + (lw / 2) - tw > 0){
ll = tw - lw;
}

this.$lens.css({
top: Math.ceil(lt),
left: Math.ceil(ll)
});

top = Math.ceil(lt * (this.$zoom.height() / th) ) * -1;
left = Math.ceil(ll * (this.$zoom.width() / tw) ) * -1;
}

this.$zoom.css({
top: top,
left: left
Expand All @@ -240,6 +277,7 @@
if (!this.isOpen) return;

this.$flyout.detach();
this.$lens.detach();
this.isOpen = false;

this.opts.onHide.call(this);
Expand Down Expand Up @@ -286,6 +324,7 @@
delete this.$image;
delete this.$notice;
delete this.$flyout;
delete this.$lens;

delete this.isOpen;
delete this.isReady;
Expand Down