Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   jQuery UI explode effect (https://javascript.ru/forum/jquery/67824-jquery-ui-explode-effect.html)

Diphenyl Oxalate 10.03.2017 17:43

jQuery UI explode effect
 
Как заставить эту дичь работать правильно?

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>explode demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.12.4.js"></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
 
<p>Click anywhere to toggle the box.</p>
<div id="toggle">
<div style="width: 100px; height: 100px; background: #ccc"></div>
</div>
 
<script>
$( document ).click(function() {
  $( "#toggle" ).toggle( "explode" );
});
</script>
 
</body>
</html>


Суть в том, что при если сделать такой html:

<div id="toggle" style="width: 100px; height: 100px; background: #ccc"></div>


то всё работает нормально, а вот если обернуть в другой блок (как в моём примере), то скрипт работает неправильно.

рони 10.03.2017 18:25

Diphenyl Oxalate,
если у блока размеры со страницу какой анимации вы хотите? ... как вариант $( "#toggle >" )

Diphenyl Oxalate 10.03.2017 18:57

Там ещё есть проблема, сдвиг при помощи margin ломает эффект.

margin: 200px (вообще ничего не видно)
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>explode demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.12.4.js"></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
 
<p>Click anywhere to toggle the box.</p>
<div id="toggle" style="margin: 200px; width: 100px; height: 100px; background: #ccc"></div>
 
<script>
$( document ).click(function() {
  $( "#toggle" ).toggle( "explode" );
});
</script>
 
</body>
</html>


margin: 50px (ячейки сильно сдвинуты)
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>explode demo</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.12.4.js"></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
 
<p>Click anywhere to toggle the box.</p>
<div id="toggle" style="margin: 50px; width: 100px; height: 100px; background: #ccc"></div>
 
<script>
$( document ).click(function() {
  $( "#toggle" ).toggle( "explode" );
});
</script>
 
</body>
</html>

рони 10.03.2017 19:19

Diphenyl Oxalate,
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>explode demo</title>
  <style type="text/css">
   body{
     position: relative;
   }
   #toggle{
     margin: 50px; width: 100px; height: 100px; background: #ccc; position: absolute;
   }
  .ui-effects-explode #toggle{
     margin: 0;
   }
  .ui-effects-explode{
     margin: -20px -8px;
  }

  </style>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.12.4.js"></script>
  <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>

<p>Click anywhere to toggle the box.</p>
<div id="toggle" ></div>

<script>
$( document ).click(function() {
  $( "#toggle" ).toggle( "explode");
});
</script>
</body>
</html>


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