-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFontLabOnline.html
240 lines (209 loc) · 9.21 KB
/
FontLabOnline.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enhanced Typography Playground</title>
<style>
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
background-color: #f0f0f0;
}
.typography-playground {
background-color: #ffffff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.controls {
margin-bottom: 20px;
}
.preview {
text-align: center;
position: relative;
}
#previewText {
margin: 0;
transition: all 0.3s ease; /* Smooth transition for changes */
text-decoration: none;
}
.code-output {
margin-top: 20px;
background-color: #f5f5f5;
padding: 10px;
border-radius: 4px;
}
#javascriptButton {
position: absolute;
bottom: 10px;
right: 10px;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
</style>
</head>
<body>
<div class="typography-playground">
<div class="controls">
<label for="fontSelector">Select Font:</label>
<select id="fontSelector"></select>
<label for="fontSize">Font Size:</label>
<input type="range" id="fontSize" min="10" max="100" value="16">
<label for="fontWeight">Font Weight:</label>
<select id="fontWeight">
<option value="normal">Normal</option>
<option value="bold">Bold</option>
</select>
<label for="fontStyle">Font Style:</label>
<select id="fontStyle">
<option value="normal">Normal</option>
<option value="italic">Italic</option>
</select>
<label for="textColor">Text Color:</label>
<input type="color" id="textColor" value="#000000">
<label for="animationPreset">Animation Preset:</label>
<select id="animationPreset">
<option value="none">None</option>
<option value="fadeIn">Fade In</option>
<option value="rotate">Rotate</option>
<option value="bounce">Bounce</option>
</select>
<label for="boxShadow">Box Shadow:</label>
<input type="text" id="boxShadow" placeholder="e.g., 2px 2px 5px #888888">
<label for="underline">Underline:</label>
<input type="checkbox" id="underline">
<label for="textAlign">Text Alignment:</label>
<select id="textAlign">
<option value="left">Left</option>
<option value="center">Center</option>
<option value="right">Right</option>
</select>
<label for="customText">Custom Text:</label>
<input type="text" id="customText" placeholder="Enter custom text">
<label for="hyperlink">Hyperlink:</label>
<input type="text" id="hyperlink" placeholder="Enter hyperlink">
</div>
<div class="preview">
<p id="previewText">Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<button id="javascriptButton" onclick="addCustomJavaScript()">Add JavaScript</button>
</div>
<div class="code-output">
<h3>Generated HTML & CSS:</h3>
<pre id="codeOutput"></pre>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const fontList = ['Arial', 'Helvetica', 'Georgia', 'Times New Roman', 'Courier New'];
const fontSelector = document.getElementById('fontSelector');
// Populate font selector
fontList.forEach(font => {
const option = document.createElement('option');
option.value = font;
option.textContent = font;
fontSelector.appendChild(option);
});
// Update preview and code every second
setInterval(updatePreviewAndCode, 1000);
// Update preview and code on control changes
document.querySelectorAll('.controls input, .controls select').forEach(function (element) {
element.addEventListener('input', updatePreviewAndCode);
});
function updatePreviewAndCode() {
updatePreview();
generateCode();
}
function updatePreview() {
const selectedFont = fontSelector.value;
const fontSize = document.getElementById('fontSize').value + 'px';
const fontWeight = document.getElementById('fontWeight').value;
const fontStyle = document.getElementById('fontStyle').value;
const textColor = document.getElementById('textColor').value;
const animationPreset = document.getElementById('animationPreset').value;
const boxShadow = document.getElementById('boxShadow').value;
const underline = document.getElementById('underline').checked;
const textAlign = document.getElementById('textAlign').value;
const customText = document.getElementById('customText').value;
const hyperlink = document.getElementById('hyperlink').value;
const previewText = document.getElementById('previewText');
previewText.textContent = customText;
previewText.style.cssText = `
font-family: ${selectedFont};
font-size: ${fontSize};
font-weight: ${fontWeight};
font-style: ${fontStyle};
color: ${textColor};
text-decoration: ${underline ? 'underline' : 'none'};
box-shadow: ${boxShadow};
text-align: ${textAlign};
${getAnimationStyle(animationPreset)}
`;
if (hyperlink) {
previewText.innerHTML = `<a href="${hyperlink}" target="_blank">${customText}</a>`;
}
}
function getAnimationStyle(preset) {
switch (preset) {
case 'fadeIn':
return 'animation: fadeIn 1s ease';
case 'rotate':
return 'animation: rotate 1s linear infinite';
case 'bounce':
return 'animation: bounce 1s ease infinite';
default:
return '';
}
}
function generateCode() {
const selectedFont = fontSelector.value;
const fontSize = document.getElementById('fontSize').value + 'px';
const fontWeight = document.getElementById('fontWeight').value;
const fontStyle = document.getElementById('fontStyle').value;
const textColor = document.getElementById('textColor').value;
const animationPreset = document.getElementById('animationPreset').value;
const boxShadow = document.getElementById('boxShadow').value;
const underline = document.getElementById('underline').checked;
const textAlign = document.getElementById('textAlign').value;
const customText = document.getElementById('customText').value;
const hyperlink = document.getElementById('hyperlink').value;
const codeOutput = document.getElementById('codeOutput');
const htmlCode = `<p id="previewText">${hyperlink ? `<a href="${hyperlink}" target="_blank">${customText}</a>` : customText}</p>`;
const cssCode = `
#previewText {
font-family: ${selectedFont};
font-size: ${fontSize};
font-weight: ${fontWeight};
font-style: ${fontStyle};
color: ${textColor};
text-decoration: ${underline ? 'underline' : 'none'};
box-shadow: ${boxShadow};
text-align: ${textAlign};
${getAnimationStyle(animationPreset)}
}
`;
codeOutput.textContent = `HTML:\n${htmlCode}\n\nCSS:\n${cssCode}`;
}
window.addCustomJavaScript = function () {
const customJavaScript = prompt("Enter your custom JavaScript code:");
if (customJavaScript) {
try {
eval(customJavaScript);
} catch (error) {
alert(`Error in executing JavaScript: ${error.message}`);
}
}
};
});
</script>
</body>
</html>