Сообщение от Black_Star
|
Не очень понял, можно подробнее, или краткий пример.
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
#field {
position: relative;
width: 400px;
height: 400px;
margin-left: 10%;
margin-top: 10%;
background-color: yellow;
border: 3px solid black;
}
.block {
float: left;
margin-left: 5%;
margin-top: 20%;
width: 40px;
height: 40px;
background-color: rgba(0, 0, 255, 1);
border: 1px solid black;
}
.block:before {
content: "";
position: absolute;
height: 0;
width: 0;
top: 40px;
border-width: 0 21.5px 40px;
border-style: solid;
/*border-color: transparent transparent rgba(0, 0, 255, 0.5);*/
border-bottom-color: rgba(0, 255, 0, 1);
border-left-color: transparent;
border-right-color: transparent;
border-top-color: transparent;
}
*!*.red{
background-color: rgba(255, 0, 0, 0.5);
}
.red:before{
border-bottom-color: rgba(255, 0, 0, 0.5);
}*/!*
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var i, r, g, b,
block = $('.block'),
allBlock = $('#field > div'),
len = allBlock.length,
but = $('#button');
but.on('click', allBlock, function () {
console.log(allBlock.length + '=blocks');
block.addClass('red')
})
})
</script>
</head>
<body>
<div id="field">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
<input id="button" type="button" value="Push me!">
</body>
</html>
Сообщение от Black_Star
|
как-то сложно к пониманию, есть что то аналогичное на jQuery ?
|
Нет.
Кстати конкретно вашу задачу можно решить использовав назначение цвета текста, оставив цвет бордера по умолчанию:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
#field {
position: relative;
width: 400px;
height: 400px;
margin-left: 10%;
margin-top: 10%;
background-color: yellow;
border: 3px solid black;
}
.block {
float: left;
margin-left: 5%;
margin-top: 20%;
width: 40px;
height: 40px;
background-color: rgba(0, 0, 255, 1);
border: 1px solid black;
*!*color: rgba(0, 255, 0, 1);*/!*
}
.block:before {
content: "";
position: absolute;
height: 0;
width: 0;
top: 40px;
border-width: 0 21.5px 40px;
border-style: solid;
/*border-color: transparent transparent rgba(0, 0, 255, 0.5);*/
border-left-color: transparent;
border-right-color: transparent;
border-top-color: transparent;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var i, r, g, b,
block = $('.block'),
allBlock = $('#field > div'),
len = allBlock.length,
but = $('#button');
but.on('click', allBlock, function () {
console.log(allBlock.length + '=blocks');
r = 255;
g = 0;
b = 0;
block.css({
backgroundColor: "rgba(" + r + ", " + g + ", " + b + ", " + 0.5 + ")",
*!*color: "rgba(" + r + ", " + g + ", " + b + ", " + 0.5 + ")"*/!*
});
})
})
</script>
</head>
<body>
<div id="field">
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
</div>
<input id="button" type="button" value="Push me!">
</body>
</html>