Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
2
2015-12-uni-ffm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CmS
2015-12-uni-ffm
Commits
b558f742
Commit
b558f742
authored
10 years ago
by
Hakim El Hattab
Browse files
Options
Downloads
Patches
Plain Diff
zoom viewport is centered on target element #900
parent
c9747563
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugin/zoom-js/zoom.js
+64
-56
64 additions, 56 deletions
plugin/zoom-js/zoom.js
with
64 additions
and
56 deletions
plugin/zoom-js/zoom.js
+
64
−
56
View file @
b558f742
...
...
@@ -16,11 +16,11 @@
})();
/*!
* zoom.js 0.
2
(modified
version
for use with reveal.js)
* zoom.js 0.
3
(modified for use with reveal.js)
* http://lab.hakim.se/zoom-js
* MIT licensed
*
* Copyright (C) 2011-201
2
Hakim El Hattab, http://hakim.se
* Copyright (C) 2011-201
4
Hakim El Hattab, http://hakim.se
*/
var
zoom
=
(
function
(){
...
...
@@ -35,8 +35,6 @@ var zoom = (function(){
var
panEngageTimeout
=
-
1
,
panUpdateInterval
=
-
1
;
var
currentOptions
=
null
;
// Check for transform support so that we can fallback otherwise
var
supportsTransforms
=
'
WebkitTransform
'
in
document
.
body
.
style
||
'
MozTransform
'
in
document
.
body
.
style
||
...
...
@@ -58,7 +56,7 @@ var zoom = (function(){
if
(
level
!==
1
&&
event
.
keyCode
===
27
)
{
zoom
.
out
();
}
}
,
false
);
}
);
// Monitor mouse movement for panning
document
.
addEventListener
(
'
mousemove
'
,
function
(
event
)
{
...
...
@@ -66,38 +64,56 @@ var zoom = (function(){
mouseX
=
event
.
clientX
;
mouseY
=
event
.
clientY
;
}
}
,
false
);
}
);
/**
* Applies the CSS required to zoom in, pr
ioritizes
use of CSS3
* Applies the CSS required to zoom in, pr
efers the
use of CSS3
* transforms but falls back on zoom for IE.
*
* @param {Number} pageOffsetX
* @param {Number} pageOffsetY
* @param {Number} elementOffsetX
* @param {Number} elementOffsetY
* @param {Object} rect
* @param {Number} scale
*/
function
magnify
(
pageOffsetX
,
pageOffsetY
,
elementOffsetX
,
elementOffsetY
,
scale
)
{
function
magnify
(
rect
,
scale
)
{
var
scrollOffset
=
getScrollOffset
();
// Ensure a width/height is set
rect
.
width
=
rect
.
width
||
1
;
rect
.
height
=
rect
.
height
||
1
;
// Center the rect within the zoomed viewport
rect
.
x
-=
(
window
.
innerWidth
-
(
rect
.
width
*
scale
)
)
/
2
;
rect
.
y
-=
(
window
.
innerHeight
-
(
rect
.
height
*
scale
)
)
/
2
;
if
(
supportsTransforms
)
{
var
origin
=
pageOffsetX
+
'
px
'
+
pageOffsetY
+
'
px
'
,
transform
=
'
translate(
'
+
-
elementOffsetX
+
'
px,
'
+
-
elementOffsetY
+
'
px) scale(
'
+
scale
+
'
)
'
;
document
.
body
.
style
.
transformOrigin
=
origin
;
document
.
body
.
style
.
OTransformOrigin
=
origin
;
document
.
body
.
style
.
msTransformOrigin
=
origin
;
document
.
body
.
style
.
MozTransformOrigin
=
origin
;
document
.
body
.
style
.
WebkitTransformOrigin
=
origin
;
document
.
body
.
style
.
transform
=
transform
;
document
.
body
.
style
.
OTransform
=
transform
;
document
.
body
.
style
.
msTransform
=
transform
;
document
.
body
.
style
.
MozTransform
=
transform
;
document
.
body
.
style
.
WebkitTransform
=
transform
;
// Reset
if
(
scale
===
1
)
{
document
.
body
.
style
.
transform
=
''
;
document
.
body
.
style
.
OTransform
=
''
;
document
.
body
.
style
.
msTransform
=
''
;
document
.
body
.
style
.
MozTransform
=
''
;
document
.
body
.
style
.
WebkitTransform
=
''
;
}
// Scale
else
{
var
origin
=
scrollOffset
.
x
+
'
px
'
+
scrollOffset
.
y
+
'
px
'
,
transform
=
'
translate(
'
+
-
rect
.
x
+
'
px,
'
+
-
rect
.
y
+
'
px) scale(
'
+
scale
+
'
)
'
;
document
.
body
.
style
.
transformOrigin
=
origin
;
document
.
body
.
style
.
OTransformOrigin
=
origin
;
document
.
body
.
style
.
msTransformOrigin
=
origin
;
document
.
body
.
style
.
MozTransformOrigin
=
origin
;
document
.
body
.
style
.
WebkitTransformOrigin
=
origin
;
document
.
body
.
style
.
transform
=
transform
;
document
.
body
.
style
.
OTransform
=
transform
;
document
.
body
.
style
.
msTransform
=
transform
;
document
.
body
.
style
.
MozTransform
=
transform
;
document
.
body
.
style
.
WebkitTransform
=
transform
;
}
}
else
{
// Reset
all values
// Reset
if
(
scale
===
1
)
{
document
.
body
.
style
.
position
=
''
;
document
.
body
.
style
.
left
=
''
;
...
...
@@ -106,11 +122,11 @@ var zoom = (function(){
document
.
body
.
style
.
height
=
''
;
document
.
body
.
style
.
zoom
=
''
;
}
//
Apply s
cale
//
S
cale
else
{
document
.
body
.
style
.
position
=
'
relative
'
;
document
.
body
.
style
.
left
=
(
-
(
page
Offset
X
+
elementOffsetX
)
/
scale
)
+
'
px
'
;
document
.
body
.
style
.
top
=
(
-
(
page
Offset
Y
+
elementOffsetY
)
/
scale
)
+
'
px
'
;
document
.
body
.
style
.
left
=
(
-
(
scroll
Offset
.
x
+
rect
.
x
)
/
scale
)
+
'
px
'
;
document
.
body
.
style
.
top
=
(
-
(
scroll
Offset
.
y
+
rect
.
y
)
/
scale
)
+
'
px
'
;
document
.
body
.
style
.
width
=
(
scale
*
100
)
+
'
%
'
;
document
.
body
.
style
.
height
=
(
scale
*
100
)
+
'
%
'
;
document
.
body
.
style
.
zoom
=
scale
;
...
...
@@ -119,11 +135,13 @@ var zoom = (function(){
level
=
scale
;
if
(
level
!==
1
&&
document
.
documentElement
.
classList
)
{
document
.
documentElement
.
classList
.
add
(
'
zoomed
'
);
}
else
{
document
.
documentElement
.
classList
.
remove
(
'
zoomed
'
);
if
(
document
.
documentElement
.
classList
)
{
if
(
level
!==
1
)
{
document
.
documentElement
.
classList
.
add
(
'
zoomed
'
);
}
else
{
document
.
documentElement
.
classList
.
remove
(
'
zoomed
'
);
}
}
}
...
...
@@ -159,7 +177,7 @@ var zoom = (function(){
function
getScrollOffset
()
{
return
{
x
:
window
.
scrollX
!==
undefined
?
window
.
scrollX
:
window
.
pageXOffset
,
y
:
window
.
scrollY
!==
undefined
?
window
.
scrollY
:
window
.
page
X
Yffset
y
:
window
.
scrollY
!==
undefined
?
window
.
scrollY
:
window
.
pageY
O
ffset
}
}
...
...
@@ -175,6 +193,7 @@ var zoom = (function(){
* - scale: can be used instead of width/height to explicitly set scale
*/
to
:
function
(
options
)
{
// Due to an implementation limitation we can't zoom in
// to another element without zooming out first
if
(
level
!==
1
)
{
...
...
@@ -188,11 +207,12 @@ var zoom = (function(){
if
(
!!
options
.
element
)
{
// Space around the zoomed in element to leave on screen
var
padding
=
20
;
var
bounds
=
options
.
element
.
getBoundingClientRect
();
options
.
width
=
options
.
element
.
getBoundingClientRect
().
width
+
(
padding
*
2
)
;
options
.
height
=
options
.
element
.
getBoundingClientRect
().
height
+
(
padding
*
2
)
;
options
.
x
=
options
.
element
.
getBoundingClientRect
().
left
-
padding
;
options
.
y
=
options
.
element
.
getBoundingClientRect
().
top
-
padding
;
options
.
x
=
bounds
.
left
-
padding
;
options
.
y
=
bounds
.
top
-
padding
;
options
.
width
=
bounds
.
width
+
(
padding
*
2
)
;
options
.
height
=
bounds
.
height
+
(
padding
*
2
)
;
}
// If width/height values are set, calculate scale from those values
...
...
@@ -204,13 +224,7 @@ var zoom = (function(){
options
.
x
*=
options
.
scale
;
options
.
y
*=
options
.
scale
;
var
scrollOffset
=
getScrollOffset
();
if
(
options
.
element
)
{
scrollOffset
.
x
-=
(
window
.
innerWidth
-
(
options
.
width
*
options
.
scale
)
)
/
2
;
}
magnify
(
scrollOffset
.
x
,
scrollOffset
.
y
,
options
.
x
,
options
.
y
,
options
.
scale
);
magnify
(
options
,
options
.
scale
);
if
(
options
.
pan
!==
false
)
{
...
...
@@ -222,8 +236,6 @@ var zoom = (function(){
}
}
currentOptions
=
options
;
}
},
...
...
@@ -234,13 +246,7 @@ var zoom = (function(){
clearTimeout
(
panEngageTimeout
);
clearInterval
(
panUpdateInterval
);
var
scrollOffset
=
getScrollOffset
();
if
(
currentOptions
&&
currentOptions
.
element
)
{
scrollOffset
.
x
-=
(
window
.
innerWidth
-
(
currentOptions
.
width
*
currentOptions
.
scale
)
)
/
2
;
}
magnify
(
scrollOffset
.
x
,
scrollOffset
.
y
,
0
,
0
,
1
);
magnify
(
{
x
:
0
,
y
:
0
},
1
);
level
=
1
;
},
...
...
@@ -256,3 +262,5 @@ var zoom = (function(){
})();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment