2

Нужно чтобы при щелчке внешний блок появлялся с помощью функции slideDown, и только после его появления внутренний абзац появлялся c помощью анимации

$('.imag').click(function(){
    $('div:last').slideDown(1000,function(){
        $('div:last p').animate(
        {
            opacity: 1;
        });
    });
});
div:last-of-type {
    width: 300px;
    height: auto;
    position: absolute;
    right: 40%;
    top:30%;
    padding-top:20px;
    background: gray;
    display: none;
}
div:last-of-type p {
    opacity: 0;
    background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<span class="imag">123</span>
<div>
    <p>Заголовок заголовок</p>
    <img src="../1304109321_324_1280.jpg" alt="картинка" style="width:100%"></div>

3 ответа 3

2

$('.button').click(function() {
  $('.hiddenDiv').slideDown(1000);
 
  setTimeout(function() {
    $('.hiddenDiv p').animate({ opacity: 1 });
  }, 1000);
});
.hiddenDiv {
  width: 300px;
  height: auto;
  position: absolute;
  right: 40%;
  top: 30%;
  padding-top: 20px;
  background: gray;
  display: none;
}
.hiddenDiv p {
  opacity: 0;
  background: white;
}
<!DOCTYPE HTML>
<html>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <meta charset="utf-8">
</head>
<body>
  <span class="button">Кнопка</span>
  <div class="hiddenDiv">
    <p>Заголовок заголовок</p>
    <img src="http://www.sourceoneinc.com/wp-content/uploads/2015/11/IMG_Client.png">
  </div>
</body>
</html>

1

Если я вас правильно понял то ошибка в синтаксисе

$('.imag').click(function() {
    $('div:last').slideDown(1000, function() {
        $('div:last p').animate({
            opacity: 1 //тут без ;
        });
    });
});
1
  • да, вы меня правильно поняли
    – Koly
    17 янв 2017 в 9:37
1

Вариант на css

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
.b {
  max-width: 300px;
  margin: 10px auto;
  border: 1px solid #ccc;
  padding: 20px;
  font-family: sans-serif;
  text-align: center;
}
.b-button {
  display: none;
}
.b-button + label {
  display: inline-block;
  padding: 15px 15%;
  background: #ccc;
  font-size: 14px;
  transition: .3s;
}
.b-button:checked + label {
  margin-bottom: 15px;
  color: #fff;
  background: green;
}
.b-button:checked + label ~ .b-inner {
  max-height: 500px;
}
.b-inner {
  background: #999;
  overflow: hidden;
  max-height: 0;
  transition: max-height 1s;
}
.b-inner > h3 {
  color: #fff;
  background: green;
  padding: 5px;
  animation: animTitle 2s linear forwards;
}
@keyframes animTitle {
  0%, 50% {
    transform: scale(0);
  }
  100% {
    transform: scale(1);
  }
}
<div class="b">
  <input type="checkbox" id="button" class="b-button">
  <label for="button">button</label>

  <div class="b-inner">
    <h3>Заголовок заголовок</h3>
    <img src="http://www.sourceoneinc.com/wp-content/uploads/2015/11/IMG_Client.png">
  </div>
</div>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.