Skip to content

Commit

Permalink
add copy to clipboard func
Browse files Browse the repository at this point in the history
  • Loading branch information
lilpacy committed Nov 15, 2024
1 parent 0f33031 commit fd2b106
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
20 changes: 18 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ class ColorVisualizerApp {
<input type="range" id="v-slider" min="0" max="100" step="1" value="0">
</div>
</div>
<div id="current-color"></div>
<div class="color-display-container">
<div id="current-color"></div>
<button id="copy-color-btn">Copy to Clipboard</button>
</div>
</div>
</div>
`;
Expand Down Expand Up @@ -289,9 +292,22 @@ class ColorVisualizerApp {

updateColorDisplay(r, g, b) {
const colorDisplay = document.getElementById('current-color');
colorDisplay.style.backgroundColor = `rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`;
const rgbValue = `rgb(${Math.round(r * 255)}, ${Math.round(g * 255)}, ${Math.round(b * 255)})`;
colorDisplay.style.backgroundColor = rgbValue;
colorDisplay.style.width = '100px';
colorDisplay.style.height = '100px';

// コピーボタンのイベントリスナーを設定
document.getElementById('copy-color-btn').addEventListener('click', () => {
navigator.clipboard.writeText(rgbValue)
.then(() => {
alert('色コードをクリップボードにコピーしました!');
})
.catch(err => {
console.error('クリップボードへのコピーに失敗しました:', err);
alert('コピーに失敗しました。');
});
});
}

animate() {
Expand Down
36 changes: 29 additions & 7 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ h1 {
margin: 0 auto;
padding: 2rem;
text-align: center;
padding-left: 300px;
padding-left: 250px;
}

.logo {
Expand Down Expand Up @@ -101,25 +101,25 @@ button:focus-visible {
top: 20px;
left: 20px;
background: rgba(0, 0, 0, 0.7);
padding: 20px;
padding: 15px;
border-radius: 10px;
color: white;
min-width: 250px;
min-width: 200px;
}

.control-section {
margin-bottom: 20px;
}

.control-section h3 {
margin: 0 0 10px 0;
font-size: 1.1em;
margin: 0 0 8px 0;
font-size: 1em;
border-bottom: 1px solid rgba(255, 255, 255, 0.3);
padding-bottom: 5px;
padding-bottom: 4px;
}

.slider-group {
margin-bottom: 10px;
margin-bottom: 8px;
}

.slider-group label {
Expand All @@ -134,6 +134,8 @@ input[type="range"] {
}

#current-color {
width: 80px !important;
height: 80px !important;
margin: 10px auto;
border-radius: 5px;
}
Expand Down Expand Up @@ -166,3 +168,23 @@ input[type="range"] {
width: 400px;
height: 400px;
}

.color-display-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}

#copy-color-btn {
padding: 8px 16px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}

#copy-color-btn:hover {
background-color: #45a049;
}

0 comments on commit fd2b106

Please sign in to comment.