@kkoshakk

Почему пропала перезагрузка страницы после применения скрипта timeout?

Есть вот такой код:

<!DOCTYPE html>
<html lang="ru-UA">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Заголовок</title>

    <!-- Bootstrap -->
    <link href="css/stylesheet.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
       <form id="my_form" class="navbar-form navbar-left" role="search">
         <div class="form-group">
           <input type="text" class="form-control" placeholder="Поиск">
            <button type="submit" class="btn btn-default">Submit</button>
         </div>
      </form>
    </nav>

  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
  <!-- Include all compiled plugins (below), or include individual files as needed -->
  <script src="js/bootstrap.js"></script>
  <script src="js/button-animation-effect.js"></script>
</body>
</html>


.navbar-inverse .navbar-form input[type=text]:focus + button,
.navbar-inverse .navbar-form input[type=password]:focus + button {
  background-color: #f0f0f0;
  outline: 0;
}
.btn {
  display: inline-block;
  margin-bottom: 0;
  font-weight: normal;
  text-align: center;
  vertical-align: middle;
  -ms-touch-action: manipulation;
      touch-action: manipulation;
  cursor: pointer;
  background-image: none;
  border: 1px solid transparent;
  white-space: nowrap;
  padding: 6px 16px;
  font-size: 13px;
  line-height: 1.846;
  border-radius: 3px;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.btn:focus,
.btn:active:focus,
.btn.active:focus,
.btn.focus,
.btn:active.focus,
.btn.active.focus {
  outline: thin dotted;
  outline: 5px auto -webkit-focus-ring-color;
  outline-offset: -2px;
}
.btn:hover,
.btn:focus,
.btn.focus {
  color: #444444;
  text-decoration: none;
}
.btn:active,
.btn.active {
  outline: 0;
  background-image: none;
  -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
  box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
}
.btn-default {
  color: #444444;
  background-color: #ffffff;
  border-color: transparent;
}
.btn-default:focus,
.btn-default.focus {
  color: #444444;
  background-color: #e6e6e6;
  border-color: rgba(0, 0, 0, 0);
  outline: 0
}
.btn-default:hover {
  color: #444444;
  background-color: #e6e6e6;
  border-color: rgba(0, 0, 0, 0);
}
.btn-default:active,
.btn-default.active,
.open > .dropdown-toggle.btn-default {
  color: #444444;
  background-color: #e6e6e6;
  border-color: rgba(0, 0, 0, 0);
}
.btn-default:active:hover,
.btn-default.active:hover,
.open > .dropdown-toggle.btn-default:hover,
.btn-default:active:focus,
.btn-default.active:focus,
.open > .dropdown-toggle.btn-default:focus,
.btn-default:active.focus,
.btn-default.active.focus,
.open > .dropdown-toggle.btn-default.focus {
  color: #444444;
  background-color: #d4d4d4;
  border-color: rgba(0, 0, 0, 0);
}
.btn-default:active,
.btn-default.active,
.open > .dropdown-toggle.btn-default {
  background-image: none;
}
.btn-default .badge {
  color: #ffffff;
  background-color: #444444;
}
















.btn-default {
  position: relative;
  overflow: hidden;
  z-index: 0;
}
.btn-default:after {
  content: "";
  position:absolute;
  width: 200%;
  height: 200%;
  top: -50%;
  left: -50%;
  z-index: -1;
  opacity: 0;
  background-color: #e0e0e0;
  background-image: -webkit-radial-gradient(circle, #e0e0e0 10%, #ffffff 11%);
  background-image: -o-radial-gradient(circle, #e0e0e0 10%, #ffffff 11%);
  background-image: radial-gradient(circle, #e0e0e0 10%, #ffffff 11%);
  background-repeat: no-repeat;
}
.btn-default:focus {
  background-color: #ffffff;
}
.btn-default:hover,
.btn-default:active:hover {
  background-color: #f0f0f0;
  outline: 0;
}
.btn-default:active {
  -webkit-box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
  box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
  -webkit-transition: all 0.4s;
  -o-transition: all 0.4s;
  transition: all 0.4s;
}
.btn-default.ripple:after {
  -webkit-animation: ripple 0.2s none;
  -moz-animation: ripple 0.2s none;
  -o-animation: ripple 0.2s none;
  animation: ripple 0.2s none;
}
@-webkit-keyframes ripple {
  0% { -webkit-transform: scale(1); opacity: 1; }
  50% { opacity: 1; }
  100%{ -webkit-transform: scale(4.8); opacity: 0; }
}
@-moz-keyframes ripple {
  0% { -moz-transform: scale(1); opacity: 1; }
  50% { opacity: 1; }
  100% { -moz-transform: scale(4.8); opacity: 0; }
}
@-o-keyframes ripple {
  0% { -o-transform: scale(1); opacity: 1; }
  50% { opacity: 1; }
  100% { -o-transform: scale(4.8); opacity: 0; }
}
@keyframes ripple {
  0% { -webkit-transform: scale(1); -moz-transform: scale(1); -ms-transform: scale(1); transform: scale(1); opacity: 1; }
  50% { opacity: 1; }
  100% { -webkit-transform: scale(4.8); -moz-transform: scale(4.8); -ms-transform: scale(4.8); transform: scale(4.8); opacity: 0; };
}
.btn {
  text-transform: uppercase;
  border: none;
  -webkit-box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.4);
  box-shadow: 1px 1px 4px rgba(0, 0, 0, 0.4);
}


//PAUSE FORM SUBMISSION
  // ====================

  $("#my_form").submit(function (event) {
    event.preventDefault();
    setTimeout(function () {
      $("#my_form").submit();
    }, 200);
    
  });


  // START ANIMATION
  // ===============

  $('.btn-default').bind("click", function() {
    $(this).addClass('ripple');
  });


Без применения jQuery скрипта при нажатии на кнопку submit происходило обновление страницы браузера, мне нужно было что бы была пауза по-больше после нажатия кнопки для анимации и я применил скрипт, но после этого обновление страницы больше не происходит. Так и должно быть или я что-то сделал не правильно? Почему до применения скрипта обновления страницы срабатывало а теперь нет?
  • Вопрос задан
  • 305 просмотров
Пригласить эксперта
Ответы на вопрос 2
alsopub
@alsopub
Попробуйте сделать (не пробовал, но по логике надо отвязать свой обработчик с preventDefault, чтобы сработал по-умолчанию):
$("#my_form").submit(function (event) {
    event.preventDefault();
    $(this).unbind('submit');
    setTimeout(function () {
      $("#my_form").submit();
    }, 200);
    
  });
Ответ написан
$("#my_form").submit(function (event) {
    var that = this;
    event.preventDefault();

    setTimeout(function () {
      that.submit(); //создать замыкание с формой
    }, 200);
    
  });
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы