index.html
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Toggle HideShow</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<button onclick="myFunction()">Click</button>
<div id="myDiv">
Here goes text.
</div>
<div class="alert">
<span class="closebtn">×</span>
<strong>Danger</strong>
</div>
<div class="alert success">
<span class="closebtn">×</span>
<strong>Success!</strong>
</div>
<div class="alert info">
<span class="closebtn">×</span>
<strong>Info</strong>
</div>
<div class="alert warning">
<span class="closebtn">×</span>
<strong>Warning!</strong>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
#myDiv {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: green;
margin-top: 20px;
}
.alert {
padding: 20px;
background-color: #f44336;
color: white;
opacity: 1;
transition: opacity 0.6s;
margin-bottom: 15px;
}
.alert.success{
background-color: #4CAF50;
}
.alert.info{
background-color: #2196F3;
}
.alert.warning{
background-color: #ff9800;
}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
script.js
// Для Toggle
function myFunction() {
var x = document.getElementById('myDiv');
if(x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
// Для Alert
var close = document.getElementsByClassName('closebtn');
var i;
for(i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.opacity = "0";
setTimeout(function(){
div.style.display = "none";
}, 600);
}
}
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Toggle HideShow</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<button onclick="myFunction()">Click</button>
<div id="myDiv">
Here goes text.
</div>
<div class="alert">
<span class="closebtn">×</span>
<strong>Danger</strong>
</div>
<div class="alert success">
<span class="closebtn">×</span>
<strong>Success!</strong>
</div>
<div class="alert info">
<span class="closebtn">×</span>
<strong>Info</strong>
</div>
<div class="alert warning">
<span class="closebtn">×</span>
<strong>Warning!</strong>
</div>
<script src="script.js"></script>
</body>
</html>
style.css
#myDiv {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: green;
margin-top: 20px;
}
.alert {
padding: 20px;
background-color: #f44336;
color: white;
opacity: 1;
transition: opacity 0.6s;
margin-bottom: 15px;
}
.alert.success{
background-color: #4CAF50;
}
.alert.info{
background-color: #2196F3;
}
.alert.warning{
background-color: #ff9800;
}
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: black;
}
script.js
// Для Toggle
function myFunction() {
var x = document.getElementById('myDiv');
if(x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
// Для Alert
var close = document.getElementsByClassName('closebtn');
var i;
for(i = 0; i < close.length; i++) {
close[i].onclick = function() {
var div = this.parentElement;
div.style.opacity = "0";
setTimeout(function(){
div.style.display = "none";
}, 600);
}
}
Комментариев нет:
Отправить комментарий