File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Source-Code/GradientBackgroundGenerator Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ document . addEventListener ( 'DOMContentLoaded' , ( ) => {
2
+ const gradient = document . getElementById ( 'gradient' ) ;
3
+ const color1 = document . querySelector ( '.color1' ) ;
4
+ const color2 = document . querySelector ( '.color2' ) ;
5
+ const cssBackground = document . getElementById ( 'css-background' ) ;
6
+ const copyBtn = document . getElementById ( 'copy-btn' ) ;
7
+
8
+ const updateBackground = ( ) => {
9
+ const color1Value = color1 . value ;
10
+ const color2Value = color2 . value ;
11
+ const background = `linear-gradient(to right, ${ color1Value } , ${ color2Value } )` ;
12
+
13
+ gradient . style . background = background ;
14
+ cssBackground . textContent = `background: ${ background } ;` ;
15
+ } ;
16
+
17
+ const copyToClipboard = ( ) => {
18
+ const textToCopy = cssBackground . textContent ;
19
+ navigator . clipboard . writeText ( textToCopy ) . then (
20
+ ( ) => {
21
+ alert ( 'CSS background value copied to clipboard!' ) ;
22
+ } ,
23
+ ( err ) => {
24
+ console . error ( 'Failed to copy: ' , err ) ;
25
+ } ,
26
+ ) ;
27
+ } ;
28
+ color1 . addEventListener ( 'input' , updateBackground ) ;
29
+ color2 . addEventListener ( 'input' , updateBackground ) ;
30
+ copyBtn . addEventListener ( 'click' , copyToClipboard ) ;
31
+ // Initialize background on page load
32
+ updateBackground ( ) ;
33
+ } ) ;
You can’t perform that action at this time.
0 commit comments