Skip to content

Commit

Permalink
i-like-robots#79 Optional delay between mouseenter and show
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Lindstrom committed Nov 12, 2015
1 parent 14079e0 commit c00ead7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dist/easyzoom.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ <h2>
<tr>
<td><var>errorDuration</var></td>
<td><code>2500</code></td>
<td>The time (in milliseconds) to display the error notice</td>
<td>The time (in milliseconds) to display the error notice.</td>
</tr>
<tr>
<td><var>preventClicks</var></td>
Expand All @@ -265,6 +265,11 @@ <h2>
<td><code>$.noop</code></td>
<td>Callback function to execute when the flyout is removed.</td>
</tr>
<tr>
<td><var>showDelay</var></td>
<td><code>0</code></td>
<td>The amount of time (in milliseconds) that should pass between mouseenter and displaying the zoom image.</td>
</tr>
</tbody>
</table>

Expand Down
37 changes: 24 additions & 13 deletions src/easyzoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
onHide: $.noop,

// Callback function to execute when the cursor is moved while over the image.
onMove: $.noop
onMove: $.noop,

// The amount of time (in milliseconds) that should pass between mouseenter and displaying the zoom image
showDelay: 0

};

Expand Down Expand Up @@ -81,25 +84,33 @@
});
}

this.$target.append(this.$flyout);
var appendFunction = $.proxy(function () {
this.$target.append(this.$flyout);

w1 = this.$target.width();
h1 = this.$target.height();

w1 = this.$target.width();
h1 = this.$target.height();
w2 = this.$flyout.width();
h2 = this.$flyout.height();

w2 = this.$flyout.width();
h2 = this.$flyout.height();
dw = this.$zoom.width() - w2;
dh = this.$zoom.height() - h2;

dw = this.$zoom.width() - w2;
dh = this.$zoom.height() - h2;
rw = dw / w1;
rh = dh / h1;

rw = dw / w1;
rh = dh / h1;
this.isOpen = true;

this.isOpen = true;
this.opts.onShow.call(this);

this.opts.onShow.call(this);
e && this._move(e);
}, this);

e && this._move(e);
if (this.opts.showDelay) {
window.setTimeout(appendFunction, this.opts.showDelay);
} else {
appendFunction();
}
};

/**
Expand Down

2 comments on commit c00ead7

@i-like-robots
Copy link

Choose a reason for hiding this comment

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

Thanks for taking the time to write and share this @slindstr.

What's the use case or problem this is trying to solve? Adding a delay would make it seem unresponsive. Is this to try and best guess the user's intention whether or not to use the zoom?

@slindstr
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the delay I completely missed your comment!

The use case I need it for is to make it a bit less jarring; I have a product page and it's common for someone to move their mouse over the product image to get to other information. Without the delay the zoom kicks in immediately and flips to the bigger image which isn't what the user was intending.

A similar example would be if you had a drop down navbar at the top of the page; if your mouse is above the navbar and you want to scroll down but hover over the nav bar, it'll expand and force you to move your mouse outside the dropdown, and then continue to scroll.

Please sign in to comment.