Skip to content

Commit

Permalink
Fix scrollbar showing when lens is off screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Doan committed Feb 29, 2016
1 parent d53631d commit 20274c4
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ You have complete control over the style and size of the lens by modifying `magn
The URI to the large image can be placed in the `data-magnify-src` attribute (as shown below) or passed as the `src` option when calling the `.magnify()` function.

```html
<img src="/images/product.jpg" data-magnify-src="/images/product-large.jpg">
<img src="/images/product.jpg" class="zoom" data-magnify-src="/images/product-large.jpg">
```

If the `data-magnify-src` attribute or `src` option is not used, then Magnify will try to grab the large image from the parent `<a>` tag, e.g.:

```html
<a href="/images/product-large.jpg">
<img src="/images/product.jpg">
<img src="/images/product.jpg" class="zoom">
</a>
```

Expand All @@ -44,7 +44,7 @@ Make sure this comes after the two required JavaScript files from Step 1 are loa
```html
<script>
$(document).ready(function() {
$('img').magnify();
$('.zoom').magnify();
});
</script>
```
Expand All @@ -54,7 +54,7 @@ Calling the `.magnify()` function with options:
```html
<script>
$(document).ready(function() {
$('img').magnify({
$('.zoom').magnify({
speed: 200,
src: '/images/product-large.jpg'
});
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "magnify",
"description": "A simple, lightweight jQuery magnifying glass zoom plugin.",
"version": "1.6.3",
"version": "1.6.5",
"main": [
"dist/css/magnify.css",
"dist/js/jquery.magnify.js"
Expand Down
7 changes: 5 additions & 2 deletions dist/css/magnify.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
html.magnifying > body {
overflow-x: hidden !important;
}
.magnify {
position: relative;
display: inline-block;
Expand All @@ -24,7 +27,7 @@
}
.magnify .magnify-lens.loading {
background: #333 !important;
opacity: .75;
opacity: 0.75;
}
.magnify .magnify-lens.loading:after {
/* Loading text */
Expand All @@ -36,6 +39,6 @@
content: 'Loading...';
font: italic normal 16px/1 Calibri, sans-serif;
text-align: center;
text-shadow: 0 0 2px rgba(51, 51, 51, .8);
text-shadow: 0 0 2px rgba(51, 51, 51, 0.8);
text-transform: none;
}
28 changes: 15 additions & 13 deletions dist/js/jquery.magnify.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* jQuery Magnify Plugin v1.6.0 by Tom Doan (http://thdoan.github.io/magnify/)
* jQuery Magnify Plugin v1.6.5 by Tom Doan (http://thdoan.github.io/magnify/)
* Based on http://thecodeplayer.com/walkthrough/magnifying-glass-for-images-using-jquery-and-css3
*
* jQuery Magnify by Tom Doan is licensed under the MIT License.
Expand All @@ -24,7 +24,12 @@
$lens,
nMagnifiedWidth = 0,
nMagnifiedHeight = 0,
sImgSrc = $image.attr('data-magnify-src') || oSettings.src || $anchor.attr('href') || '';
sImgSrc = $image.attr('data-magnify-src') || oSettings.src || $anchor.attr('href') || '',
hideLens = function() {
if ($lens.is(':visible')) $lens.fadeOut(oSettings.speed, function() {
$('html').removeClass('magnifying'); // Reset overflow
});
};
// Disable zooming if no valid zoom image source
if (!sImgSrc) return;

Expand Down Expand Up @@ -85,9 +90,12 @@
// Toggle magnifying lens
if (!$lens.is(':animated')) {
if (nX<$container.width() && nY<$container.height() && nX>0 && nY>0) {
if ($lens.is(':hidden')) $lens.fadeIn(oSettings.speed);
if ($lens.is(':hidden')) {
$('html').addClass('magnifying'); // Hide overflow while zooming
$lens.fadeIn(oSettings.speed);
}
} else {
if ($lens.is(':visible')) $lens.fadeOut(oSettings.speed);
hideLens();
}
}
if ($lens.is(':visible')) {
Expand Down Expand Up @@ -118,20 +126,14 @@
});

// Prevent magnifying lens from getting "stuck"
$container.mouseleave(function() {
if ($lens.is(':visible')) $lens.fadeOut(oSettings.speed);
});
$container.mouseleave(hideLens);
if (oSettings.timeout>=0) {
$container.on('touchend', function() {
setTimeout(function() {
if ($lens.is(':visible')) $lens.fadeOut(oSettings.speed);
}, oSettings.timeout);
setTimeout(hideLens, oSettings.timeout);
});
}
// Ensure lens is closed when tapping outside of it
$('body').not($container).on('touchstart', function() {
if ($lens.is(':visible')) $lens.fadeOut(oSettings.speed);
});
$('body').not($container).on('touchstart', hideLens);

if ($anchor.length) {
// Make parent anchor inline-block to have correct dimensions
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "magnify",
"version": "1.6.3",
"version": "1.6.5",
"description": "A simple, lightweight jQuery magnifying glass zoom plugin.",
"keywords": [
"jquery-plugin",
Expand Down

0 comments on commit 20274c4

Please sign in to comment.