Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Created February 23, 2022 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelibaceta/f04a7b1ac1ecd011184346e87e28e4c9 to your computer and use it in GitHub Desktop.
Save joelibaceta/f04a7b1ac1ecd011184346e87e28e4c9 to your computer and use it in GitHub Desktop.
Ejercicio Funciones
#colour_container {
width: 150px;
height: 150px;
background-color: black;
}
.color-option {
width: 50px;
height: 50px;
}
#red {
/* Color de fondo: rojo */
background-color: red;
}
#green {
background-color: green;
}
#blue {
background-color: blue;
}
.color-selectors {
display: flex;
}
<html>
<head>
<link rel="stylesheet" href="estilos.css" />
</head>
<body>
<div id="colour_container">
<!-- Cuadro de color principal -->
</div>
<div class="color-selectors">
<div id="red"
onmouseover="selectColor(this, 'red')"
onmouseout="cleanColors(this)"
class="color-option"></div>
<div id="blue"
onmouseover="selectColor(this, 'blue')"
onmouseout="cleanColors(this)"
class="color-option"></div>
<div id="green"
onmouseover="selectColor(this, 'green')"
onmouseout="cleanColors(this)"
class="color-option"></div>
</div>
<script src="script.js"></script>
</body>
</html>
function redSelected() {
var mainColourE = document.getElementById("colour_container")
mainColourE.style.backgroundColor = "red"
}
function selectColor(e, color) {
// Esta funcion cambia de color de fondo al el elemento
// identificado con el Id colour_container, el color es
// recibido a traves del parametro color
var mainColourE = document.getElementById("colour_container")
mainColourE.style.backgroundColor = color
// Otra alternativa
// mainColourE.style.backgroundColor = e.style.backgroundColor
//e.style.width = "60px";
e.style.height = "60px";
}
function cleanColors(e){
var mainColourE = document.getElementById("colour_container")
mainColourE.style.backgroundColor = "black"
//e.style.width = "50px";
e.style.height = "50px";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment