-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
345 lines (282 loc) · 9.69 KB
/
index.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>INSTACUT</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.6.0/jszip.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<style>
body {
background-color: #f0eae3;
font-family: 'Arial', sans-serif;
text-align: center;
margin: 0;
padding: 0;
}
.title-top {
z-index: -1;
font-size: 17vw;
font-weight: bold;
color: white;
overflow: hidden;
}
.content{
position: sticky;
display: block;
width: 100%;
height: 100%;
padding-bottom: 10%;
margin-top: -20%;
transition: margin-top 0.3s;
background-color: #ffffff;
}
.white{
z-index: -1;
position: fixed;
background-color: #fff;
margin-top: 50%;
width: 100%;
height: 100%;
}
#uploadButton, #downloadButton {
padding: 10px 20px;
font-size: 2em;
background-color: #a7cbd9;
border: none;
border-radius: 5px;
cursor: pointer;
color: white;
}
#previewContainer::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-image: repeating-linear-gradient(
-45deg,
rgba(0, 0, 0, 0),
rgba(0, 0, 0, 0) 10px,
rgba(128, 128, 128, 0.5) 10px,
rgba(128, 128, 128, 0.5) 20px
);
pointer-events: none;
z-index: 1;
}
#previewContainer .preview-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: rgba(128, 128, 128, 0.5);
font-size: 5em;
z-index: 2;
}
#previewContainer {
position: relative;
width: 700px;
height: 200px;
margin: auto;
margin-top: 3%;
margin-bottom: 1%;
background-color: #fff;
border: 1px solid #ddd;
display: none; /* Initially hidden */
}
.partition-preview {
position: absolute;
width: 200px;
height: 200px;
border-left: 50px solid white;
background-color: #ddd;
}
.partition-preview:nth-child(2) { left: 250px; }
.partition-preview:nth-child(3) { left: 500px; }
#previewContainer img {
width: 100%;
height: auto;
z-index: 0;
}
.drop-zone {
position: relative;
border: 2px dashed #a7cbd9;
padding: 20px;
margin: 5%;
cursor: pointer;
overflow: hidden;
}
.drop-zone.over::before {
content: '';
position: absolute;
top: 50%;
left: 50%;
width:88%;
height: 88%;
border: 2px dotted #a7cbd9;
border-radius: 10px;
animation: fadeAndPulse 2s infinite alternate;
transform: translate(-50%, -50%);
}
.drop-zone.over::after {
content: '';
opacity: 0;
position: absolute;
top: 50%;
left: 50%;
width: 80%;
height: 80%;
border: 2px dotted #a7cbd9;
border-radius: 10px;
animation: pulse 2s infinite alternate;
transform: translate(-50%, -50%);
animation: fadeAndPulse 2s infinite alternate;
transform: translate(-50%, -50%);
animation-delay: 0.5s;
}
@keyframes fadeAndPulse {
0%, 100% {
opacity: 0;
transform: translate(-50%, -50%) scale(1);
border-color: #a7cbd9;
}
100% {
opacity: 1;
transform: translate(-50%, -50%) scale(1.1);
border-color: #b3ffb3;
}
}
.hidden {
opacity: 0;
transition: opacity 0.3s ease;
}
</style>
</head>
<body>
<div class="title-top">INSTACUT</div>
<div class="content">
<div class="drop-zone" id="dropZone">
<input type="file" id="uploadButton" accept="image/*" />
</div>
<button id="downloadButton" onclick="downloadZip()" style="display: none;">Télécharger les différentes parties</button>
<div id="previewContainer"></div>
</div>
</body>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Selecting elements from the DOM
const content = document.querySelector('.content');
const dropZone = document.getElementById('dropZone');
const uploadButton = document.getElementById('uploadButton');
const previewContainer = document.getElementById('previewContainer');
const downloadButton = document.getElementById('downloadButton');
let zip = new JSZip(); // Initializing JSZip for creating ZIP files
// Initial animation for the page content
setTimeout(function() {
content.style.marginTop = '-8%';
}, 100);
// Event handlers for drag & drop functionality
dropZone.addEventListener('dragover', (e) => {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // Indicate a copy action on dragover
dropZone.classList.add('over'); // Add styling class for dragover
uploadButton.classList.add('hidden'); // Hide the upload button on dragover
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('over'); // Remove styling class when drag leaves
uploadButton.classList.remove('hidden'); // Show the upload button again
});
// Handling the drop event
dropZone.addEventListener('drop', (e) => {
e.stopPropagation();
e.preventDefault();
dropZone.classList.remove('over');
uploadButton.classList.remove('hidden');
const files = e.dataTransfer.files;
if (files.length > 0) {
processFile(files[0]); // Process the dropped file
}
});
// Handle file selection from the input
uploadButton.addEventListener('change', function(e) {
if (e.target.files.length > 0) {
processFile(e.target.files[0]); // Process the selected file
}
});
// Function to process the file
function processFile(file) {
partitionImage(file); // Partition the image
downloadButton.style.display = 'none'; // Hide the download button initially
previewContainer.innerHTML = ''; // Clear the preview container
previewContainer.style.display = 'none'; // Hide the preview container initially
zip = new JSZip(); // Reset the zip file
}
// Function to partition the image and set up previews
function partitionImage(file) {
const reader = new FileReader();
reader.onload = function(e) {
const img = new Image();
img.onload = function() {
const partWidth = Math.round(img.width / 3); // Calculate width for each partition
const scaleFactor = 200 / img.height; // Calculate scale factor based on desired height
previewContainer.innerHTML = ''; // Clear existing previews
previewContainer.style.display = 'flex'; // Display the container as flex
previewContainer.style.alignItems = 'center';
previewContainer.style.justifyContent = 'center';
// Loop through each partition
for (let i = 0; i < 3; i++) {
if (i > 0) {
// Add a spacer div for margin between previews
const spacer = document.createElement('div');
spacer.style.width = '10px'; // Set spacer width
previewContainer.appendChild(spacer);
}
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = partWidth; // Set canvas width to partition width
canvas.height = img.height; // Set canvas height to image height
// Draw the image partition on the canvas
ctx.drawImage(img, partWidth * i, 0, partWidth, img.height, 0, 0, partWidth, img.height);
// Convert canvas to an image for preview
const dataURL = canvas.toDataURL();
const previewImg = new Image();
previewImg.src = dataURL;
previewImg.style.height = '200px'; // Set height for preview
previewImg.style.width = `${partWidth * scaleFactor}px`; // Scale width to maintain aspect ratio
previewContainer.appendChild(previewImg); // Add preview image to container
// Add the canvas content to the ZIP file
canvas.toBlob(function(blob) {
zip.file(`partition_${i + 1}.png`, blob);
}, 'image/png');
}
downloadButton.style.display = 'inline-block'; // Show download button after processing
};
img.src = e.target.result; // Read the file as an image source
};
reader.readAsDataURL(file);
}
// Function to download the ZIP file
function downloadZip() {
zip.generateAsync({type: "blob"})
.then(function(content) {
saveAs(content, "partitions.zip"); // Trigger the download of the ZIP file
});
}
// Event listener for download button
downloadButton.addEventListener('click', downloadZip);
// Event listener for window scroll
window.addEventListener('scroll', function() {
// Calculate the scroll percentage relative to the window height
let scrollPercentage = window.scrollY / window.innerHeight;
// Dynamically adjust the top margin of the content based on the scroll percentage
let newMarginTop = -8 - (scrollPercentage * 12);
newMarginTop = Math.max(-20, Math.min(-3, newMarginTop));
// Apply the calculated top margin to the content element
content.style.marginTop = newMarginTop + '%';
});
});
</script>
</body>
</html>