Сообщение от Black_Star
|
По нажатию на один из дивов им присваивается значения функция move(); Как по нажатию на элемент #button действия произведенные функцией убирать ? Возврат в изначальное состояние.
|
Как вариант...
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251' />
<script src='http://code.jquery.com/jquery-latest.js'></script>
<!--
<script src="https://code.angularjs.org/1.3.9/angular.min.js"></script>
<script src="https://code.angularjs.org/1.3.9/angular-route.js"></script>
-->
<style type='text/css'>
#field {
position: relative;
width: 300px;
height: 300px;
background-color: red;
}
.square {
position: absolute;
width: 50px;
height: 50px;
background-color: black;
border: 1px solid white;
color: white;
font-size: 1.5em;
text-align: center;
cursor: pointer;
}
.square:nth-child(1) {
top: 10%;
left: 20%;
}
.square:nth-child(2) {
top: 40%;
left: 20%;
}
.square:nth-child(3) {
top: 60%;
left: 20%;
}
.square:nth-child(4) {
top: 80%;
left: 20%;
}
#bottom{
width: 300px;
height: 100%;
background-color: green;
cursor: pointer;
font-size: 1.5em;
color: white;
}
</style>
<script type='text/javascript'>
$(function() {
$('#field').on('click', 'div', move);
$('#button').on('click', function() {
// сюда надо что-то написать ? =)
var newDiv = $('#field > div');
newDiv.eq(0).css({'top':'',
'left':''});
newDiv.eq(1).css({'top':'',
'left':''});
newDiv.eq(2).css({'top':'',
'left':''});
newDiv.eq(3).css({'top':'',
'left':''});
})
});
function move () {
var newDiv = $('#field > div');
newDiv.eq(0).css({'top':'5%',
'left':'41%'});
newDiv.eq(1).css({'top':'15%',
'left':'57%'});
newDiv.eq(2).css({'top':'65%',
'left':'57%'});
newDiv.eq(3).css({'top':'65%',
'left':'25%'});
}
</script>
</head>
<body>
<div id="field">
<div class="square">1</div>
<div class="square">2</div>
<div class="square">3</div>
<div class="square">4</div>
</div>
<div id="button">Clear function</div>
</body>
</html>