Skip to content

Commit

Permalink
feat: Add gap configuration item to zoom-image
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyib committed Feb 24, 2020
1 parent e994ee3 commit aa918d3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ zoom_image:
# The color of mask.
# (Please use "" to wrap the value)
mask_color: "rgba(0,0,0,0.6)"
# The gap between image and a edge of screen when image is enlarged.
# (Only `px` unit is supported)
gap_aside: 20px

# If you are use "photos" attribute in the Front-matter,
# you can enable this to show images in waterfalls flow.
Expand Down
2 changes: 2 additions & 0 deletions docs/zh-CN/advanced/advanced-setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,8 @@ zoom_image:
enable: true
# 遮罩的颜色
mask_color: "rgba(0,0,0,0.6)"
# 图片放大时,距离屏幕边缘的间隙
gap_aside: 20px
```

::: tip
Expand Down
9 changes: 5 additions & 4 deletions source/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,21 @@ Stun.utils = Stun.$u = {
.clone()
.addClass('zoomimg-clone');

var SIDE_GAP = parseInt(CONFIG.zoom_image.gap_aside || 20);
var imgRect = this.getBoundingClientRect();
var imgOuterW = $(this).outerWidth();
var imgOuterH = $(this).outerHeight();
var imgW = $(this).width();
var imgH = $(this).height();
var imgL = $(this).offset().left + (imgOuterW - imgW) / 2;
var imgT = $(this).offset().top + (imgOuterH - imgH) / 2;
var winW = $(window).width();
var winH = $(window).height();
var winW = $(window).width() - SIDE_GAP * 2;
var winH = $(window).height() - SIDE_GAP * 2;
var scaleX = winW / imgW;
var scaleY = winH / imgH;
var scale = (scaleX < scaleY ? scaleX : scaleY) || 1;
var translateX = winW / 2 - (imgRect.x + imgOuterW / 2);
var translateY = winH / 2 - (imgRect.y + imgOuterH / 2);
var translateX = winW / 2 - (imgRect.x + imgOuterW / 2) + SIDE_GAP;
var translateY = winH / 2 - (imgRect.y + imgOuterH / 2) + SIDE_GAP;

$(this).addClass('zoomimg--hide');
$('body')
Expand Down

0 comments on commit aa918d3

Please sign in to comment.