Refactor animeCat.js to improve layout and structure
This commit is contained in:
92
animeCat.js
92
animeCat.js
@@ -1,7 +1,3 @@
|
|||||||
// animeCat.js
|
|
||||||
// miau!
|
|
||||||
|
|
||||||
|
|
||||||
window.AnimeCat = class AnimeCat {
|
window.AnimeCat = class AnimeCat {
|
||||||
/**
|
/**
|
||||||
* @param {HTMLElement} container
|
* @param {HTMLElement} container
|
||||||
@@ -37,52 +33,61 @@ window.AnimeCat = class AnimeCat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_createElements() {
|
_createElements() {
|
||||||
// Flexbox: Katze und Bubble nebeneinander
|
// Outer wrapper (relativ für absolute Kinder!)
|
||||||
this.wrapper = document.createElement('div');
|
this.wrapper = document.createElement('div');
|
||||||
Object.assign(this.wrapper.style, {
|
Object.assign(this.wrapper.style, {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
|
width: '100px',
|
||||||
|
height: '80px',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'flex-end',
|
alignItems: 'flex-end',
|
||||||
minHeight: '60px',
|
zIndex: 1
|
||||||
minWidth: '180px',
|
|
||||||
zIndex: '1'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// --- Glow ---
|
// --- Glow (unter der Katze) ---
|
||||||
this.glow = document.createElement('div');
|
this.glow = document.createElement('div');
|
||||||
this.glow.id = 'cat-glow';
|
this.glow.id = 'cat-glow';
|
||||||
// CSS hier ODER besser via <style> im Head! Aber ein Minimalstyle, falls alles fehlt:
|
|
||||||
Object.assign(this.glow.style, {
|
Object.assign(this.glow.style, {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: '0',
|
left: '50%',
|
||||||
top: '0',
|
top: '50%',
|
||||||
width: '120px',
|
transform: 'translate(-50%, -52%)',
|
||||||
height: '80px',
|
borderRadius: '50%',
|
||||||
pointerEvents: 'none',
|
width: '120px',
|
||||||
zIndex: 1
|
height: '80px',
|
||||||
|
pointerEvents: 'none',
|
||||||
|
zIndex: 1,
|
||||||
|
transition: 'background 0.4s, width 0.2s, height 0.2s, opacity 0.3s'
|
||||||
});
|
});
|
||||||
|
this.wrapper.appendChild(this.glow);
|
||||||
|
|
||||||
// --- Cat image ---
|
// --- Cat image (über Glow) ---
|
||||||
this.img = document.createElement('img');
|
this.img = document.createElement('img');
|
||||||
this.img.src = this.images.default;
|
this.img.src = this.images.default;
|
||||||
|
Object.assign(this.img.style, {
|
||||||
|
position: 'absolute',
|
||||||
|
left: '50%',
|
||||||
|
top: '50%',
|
||||||
|
transform: 'translate(-50%, -60%)',
|
||||||
|
width: '62px',
|
||||||
|
height: '50px',
|
||||||
|
zIndex: 2,
|
||||||
|
userSelect: 'none',
|
||||||
|
webkitUserSelect: 'none',
|
||||||
|
MozUserSelect: 'none',
|
||||||
|
msUserSelect: 'none',
|
||||||
|
webkitUserDrag: 'none',
|
||||||
|
pointerEvents: 'auto'
|
||||||
|
});
|
||||||
this.img.draggable = false;
|
this.img.draggable = false;
|
||||||
this.img.style.userSelect = 'none';
|
this.wrapper.appendChild(this.img);
|
||||||
this.img.style.webkitUserSelect = 'none';
|
|
||||||
this.img.style.MozUserSelect = 'none';
|
|
||||||
this.img.style.msUserSelect = 'none';
|
|
||||||
this.img.style.webkitUserDrag = 'none';
|
|
||||||
this.img.style.width = '62px';
|
|
||||||
this.img.style.height = '50px';
|
|
||||||
this.img.style.zIndex = '2';
|
|
||||||
this.img.style.position = 'relative'; // wichtig für Layering
|
|
||||||
|
|
||||||
// --- Speech bubble ---
|
// --- Speech bubble (daneben, nicht überlagert) ---
|
||||||
this.bubble = document.createElement('div');
|
this.bubble = document.createElement('div');
|
||||||
Object.assign(this.bubble.style, {
|
Object.assign(this.bubble.style, {
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
marginLeft: '14px',
|
marginLeft: '14px',
|
||||||
marginBottom: '11px',
|
marginBottom: '11px',
|
||||||
padding: '10px 16px',
|
padding: '10px 16px',
|
||||||
background: 'white',
|
background: 'white',
|
||||||
border: '1px solid #ccc',
|
border: '1px solid #ccc',
|
||||||
@@ -97,7 +102,7 @@ window.AnimeCat = class AnimeCat {
|
|||||||
color: '#333',
|
color: '#333',
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
minHeight: '30px',
|
minHeight: '30px',
|
||||||
zIndex: '10',
|
zIndex: 10,
|
||||||
overflowWrap: 'anywhere',
|
overflowWrap: 'anywhere',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center'
|
alignItems: 'center'
|
||||||
@@ -115,33 +120,24 @@ window.AnimeCat = class AnimeCat {
|
|||||||
borderBottom: '8px solid transparent',
|
borderBottom: '8px solid transparent',
|
||||||
borderRight: '13px solid #fff',
|
borderRight: '13px solid #fff',
|
||||||
filter: 'drop-shadow(-2px 1px 2px rgba(0,0,0,0.10))',
|
filter: 'drop-shadow(-2px 1px 2px rgba(0,0,0,0.10))',
|
||||||
zIndex: '11'
|
zIndex: 11
|
||||||
});
|
});
|
||||||
this.bubble.appendChild(this.bubblePointer);
|
this.bubble.appendChild(this.bubblePointer);
|
||||||
|
|
||||||
// --- Zusammenbauen ---
|
// --- Wrapper komplettieren ---
|
||||||
if (!this.wrapper.querySelector('#cat-glow')) {
|
|
||||||
this.glow = document.createElement('div');
|
|
||||||
this.glow.id = 'cat-glow';
|
|
||||||
this.wrapper.insertBefore(this.glow, this.img);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.wrapper.appendChild(this.glow);
|
|
||||||
this.wrapper.appendChild(this.img);
|
|
||||||
this.wrapper.appendChild(this.bubble);
|
this.wrapper.appendChild(this.bubble);
|
||||||
this.container.appendChild(this.wrapper);
|
this.container.appendChild(this.wrapper);
|
||||||
|
|
||||||
|
// --- Herz-Emitter (für Animationen) ---
|
||||||
// Emitter für Herzen (abgekoppelt!)
|
|
||||||
this.heartEmitter = document.createElement('div');
|
this.heartEmitter = document.createElement('div');
|
||||||
Object.assign(this.heartEmitter.style, {
|
Object.assign(this.heartEmitter.style, {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
left: '82px', // rechts neben der Katze
|
left: '82px',
|
||||||
bottom: '32px',
|
bottom: '32px',
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
width: '1px',
|
width: '1px',
|
||||||
height: '1px',
|
height: '1px',
|
||||||
zIndex: 20
|
zIndex: 20
|
||||||
});
|
});
|
||||||
this.container.appendChild(this.heartEmitter);
|
this.container.appendChild(this.heartEmitter);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user