Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Как добавить плавность к открытию модального окна? (https://javascript.ru/forum/misc/82364-kak-dobavit-plavnost-k-otkrytiyu-modalnogo-okna.html)

jurvrn 23.04.2021 17:42

Как добавить плавность к открытию модального окна?
 
есть такой код, как к нему можно добавить плавность открытия и закрытия модального окна? чтобы сильно не менять код
<button id="openformeven" class="btn_open" onclick="document.getElementById('cls_ctnr').style.display='inline-block'; return false;">ОТКРЫТЬ</button>

<div id="cls_ctnr">
  <div id="cls_pop">
    <span class="cls_close" onclick="document.getElementById('cls_ctnr').style.display='none'; return false;">&#9776</span>
    <h4>Заголовок</h4>
    Пример модального окна.
  </div>
</div>

<!--СТИЛИ-->
<style>
#cls_ctnr {
  display: none;
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  text-align: center;
  z-index: 99;
}

#cls_ctnr::after {
  display: inline-block;
  vertical-align: middle;
  width: 0;
  height: 100%;
  content: "";
}

#cls_pop {
  padding: 40px 10px 10px;
  min-height: 200px;
  max-width: 450px;
  display: inline-block;
  vertical-align: middle;
  position: relative;
  text-align: center;
  background: #b2c494;
  color: #fff;
}

#cls_pop h4 {
  margin: 0;
  text-align: center;
  font-size: 21px;
  color: darkblue;
}

.cls_close {
  display: block;
  position: absolute;
  background: #6700ff;
  top: -15px;
  right: -15px;
  margin-left: -25px;
  line-height: 30px;
  font-weight: bold;
  width: 30px;
  height: 30px;
  text-align: center;
  color: #fff;
  cursor: pointer;
  -webkit-border-radius: 50px;
  -moz-border-radius: 50px;
  border-radius: 50px;
}

.cls_close:hover {
  background: #eaade7;
  color: #000;
}
.btn_open {background-color: slateblue}

</style>

jurvrn 24.04.2021 10:52

upd. решил добавить ещё свойство на клик transition='3s linear'; , но не сработало
<button id="openformeven" class="btn_open" onclick="document.getElementById('cls_ctnr').style.display='inline-block',transition='3s linear'; return false;">ОТКРЫТЬ</button>

рони 24.04.2021 12:19

Цитата:

Сообщение от jurvrn
решил добавить

... :(

рони 24.04.2021 12:32

модальное окно transition
 
jurvrn,
<!DOCTYPE html>
<html>
<head>
    <title>Untitled</title>
    <meta charset="utf-8">
    <style>
#cls_ctnr {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    text-align: center;
    z-index: 99;
    transform:  scale(0);
    transition: opacity 1s, transform 0s 1s;
    opacity: 0;
}
#cls_ctnr.open{
    transform:  scale(1);
    transition: opacity 1s, transform 0s 0s;
    opacity: 1;
}
#cls_ctnr::after {
    display: inline-block;
    vertical-align: middle;
    width: 0;
    height: 100%;
    content: "";
}
#cls_pop {
    padding: 40px 10px 10px;
    min-height: 200px;
    max-width: 450px;
    display: inline-block;
    vertical-align: middle;
    position: relative;
    text-align: center;
    background: #b2c494;
    color: #fff;
}
#cls_pop h4 {
    margin: 0;
    text-align: center;
    font-size: 21px;
    color: darkblue;
}
.cls_close {
    display: block;
    position: absolute;
    background: #6700ff;
    top: -15px;
    right: -15px;
    margin-left: -25px;
    line-height: 30px;
    font-weight: bold;
    width: 30px;
    height: 30px;
    text-align: center;
    color: #fff;
    cursor: pointer;
    -webkit-border-radius: 50px;
    -moz-border-radius: 50px;
    border-radius: 50px;
}
.cls_close:hover {
    background: #eaade7;
    color: #000;
}
.btn_open {background-color: slateblue}
</style>
</head>
<body>
<button id="openformeven" type="button" class="btn_open" onclick="document.getElementById('cls_ctnr').classList.add('open')" >ОТКРЫТЬ</button>
<div id="cls_ctnr">
    <div id="cls_pop">
        <span class="cls_close" onclick="document.getElementById('cls_ctnr').classList.remove('open')">&#9776</span>
        <h4>Заголовок</h4>
        Пример модального окна.
    </div>
</div>
</body>
</html>

рони 24.04.2021 12:37

jurvrn,
https://javascript.ru/forum/xhtml-ht...tml#post522227

jurvrn 24.04.2021 16:46

рони,
понял что через замену стилей, спасибо!


Часовой пояс GMT +3, время: 01:33.