-
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.
- Loading branch information
Showing
4 changed files
with
264 additions
and
8 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
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,54 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>图片裁剪上传原理</title> | ||
<style> | ||
img { | ||
width: 300px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<input type="file" /><br /> | ||
<img src="" alt="" class="preview" /> | ||
<script> | ||
const input = document.querySelector('input') | ||
const preview = document.querySelector('.preview') | ||
input.onchange = (e) => { | ||
const file = e.target.files[0] | ||
const reader = new FileReader() | ||
reader.onload = (e) => { | ||
preview.src = e.target.result | ||
} | ||
reader.readAsDataURL(file) | ||
} | ||
|
||
// 交互 | ||
|
||
// 上传 | ||
// 获取裁剪后的 file 对象 | ||
function cut() { | ||
const cutInfo = { | ||
x: 2000, | ||
y: 1000, | ||
oWidth: 1000, | ||
oHeight: 1000, | ||
width: 200, | ||
height: 200, | ||
} | ||
const cvs = document.createElement('canvas') | ||
const ctx = cvs.getContext('2d') | ||
cvs.width = cutInfo.width | ||
cvs.height = cutInfo.height | ||
ctx.drawImage(preview, cutInfo.x, cutInfo.y, cutInfo.oWidth, cutInfo.oHeight, 0, 0, cutInfo.width, cutInfo.height) | ||
cvs.toBlob((blob) => { | ||
const file = new File([blob], 'cut.png', { | ||
type: 'image/png', | ||
}) | ||
}) | ||
} | ||
</script> | ||
</body> | ||
</html> |
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,67 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>环绕式照片墙</title> | ||
<link rel="stylesheet" href="./demo.css" /> | ||
<style> | ||
/* @use 'sass:math'; | ||
|
||
body { | ||
background: #000; | ||
perspective: 2000px; | ||
} | ||
|
||
.ring { | ||
width: 100vw; | ||
height: 100vh; | ||
transform-style: preserve-3d; | ||
transform: rotate(340deg, 20deg); // 改变 y 轴坐标即可以转动 | ||
|
||
img { | ||
position: absolute; | ||
$imgWidth: 300px; | ||
$imgHeight: 400px; | ||
width: $imgWidth; | ||
height: $imgHeight; | ||
left: 50%; | ||
top: 50%; | ||
margin-left: -$imgWidth / 2; | ||
margin-top: -$imgHeight / 2; | ||
$r: 500px; | ||
$n: 10; | ||
$pDeg: 360deg / $n; | ||
backface-visibility: hidden; | ||
opacity: 0.5; | ||
transition: opcacity 0.2s; | ||
&:hover { | ||
opacity: 1; | ||
} | ||
@for $i from 0 through $n - 1 { | ||
&:nth-child(#{$i + 1}) { | ||
$deg: $i * $pDeg; | ||
$x: math.sin($deg) * $r; | ||
$z: math.cos($deg) * $r; | ||
transform: translate3d(#{$x}, 0, #{$z}) rotateY(-180deg + $deg); | ||
} | ||
} | ||
} | ||
} */ | ||
</style> | ||
</head> | ||
<body> | ||
<div class="ring"> | ||
<img src="https:picsum.photos/id/21/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/22/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/23/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/24/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/25/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/26/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/27/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/28/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/29/400/600/" alt="" /> | ||
<img src="https:picsum.photos/id/30/400/600/" alt="" /> | ||
</div> | ||
</body> | ||
</html> |
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