forked from timmywil/panzoom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(constrain): add contain:true option (timmywil#598)
- Loading branch information
Showing
4 changed files
with
125 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Panzoom, { PanzoomObject } from '../../src/panzoom' | ||
import React, { useEffect, useRef } from 'react' | ||
|
||
import Code from '../Code' | ||
import Demo from '../Demo' | ||
|
||
const code = <Code>{`Panzoom(elem, { contain: true })`}</Code> | ||
|
||
export default function ContainTrue() { | ||
const elem = useRef<HTMLDivElement>(null) | ||
let panzoom: PanzoomObject | ||
useEffect(() => { | ||
panzoom = Panzoom(elem.current, { contain: true, startScale: 1.3 }) | ||
panzoom.pan(10, 10, { relative: true }) | ||
const parent = elem.current.parentElement | ||
parent.addEventListener('wheel', function (event) { | ||
if (!event.shiftKey) { | ||
return | ||
} | ||
panzoom.zoomWithWheel(event) | ||
}) | ||
}, []) | ||
return ( | ||
<Demo title="Containment within the parent" code={code}> | ||
<div className="buttons"> | ||
<label>Try me: </label> | ||
<button | ||
onClick={() => { | ||
panzoom.zoomIn() | ||
}} | ||
> | ||
Zoom in | ||
</button> | ||
<button | ||
onClick={() => { | ||
panzoom.zoomOut() | ||
}} | ||
> | ||
Zoom out | ||
</button> | ||
<button | ||
onClick={() => { | ||
panzoom.reset() | ||
}} | ||
> | ||
Reset | ||
</button> | ||
</div> | ||
<div className="panzoom-parent"> | ||
<div | ||
className="panzoom" | ||
ref={elem} | ||
style={{ | ||
background: '#000', | ||
width: '400px', | ||
border: '2px dotted #ff0', | ||
margin: '0 auto' | ||
}} | ||
> | ||
<img style={{ width: '100%', height: '100%' }} src="awesome_tiger.svg" /> | ||
</div> | ||
</div> | ||
</Demo> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6d4748a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing solved zoomed element still getting out of div