javascript - 我如何对这个扩展了 onclick 的 div 使用缓动效果,以及对其中的元素淡入淡出效果?

标签 javascript jquery css jquery-animate easing

我有两个问题,

1) 我有一个扩展 onclick 的 div,(.panel) 我怎样才能对其使用缓动以使其以平滑的方式打开?

2) 如何让扩展的 div (.panel) 中的 ul 列表在 div 扩展后的几毫秒内淡出?

<div id="effect" class="mores" style="background-color: brown">
<div class="panel">click
    <ul>
        <li>Coffee</li>
        <li>Tea</li>
        <li>Milk</li>
    </ul>
</div>

JS

 var next_move = "expand";
$(document).ready(function () {
 $(".panel").click(function () {
     console.log(next_move);
     var css = {};
     if (next_move == "expand") {
         css = {
             width: '210px',
             height: '170px'
         };
         next_move = "shrink";
     } else {
         css = {
             width: '30px',
             height: '20px'
         };
         console.log('hi');
         next_move = "expand";
     }
     $(this).animate(css, 200);
 });
});




     .panel {
      width: 30px;
      height: 21px;
      overflow: hidden;
      color:white;
      background-color: grey;
  }
      .panel ul {
       margin-left:10%;
       color:white;
 }
      .mores {
      width: 210px;
      height: 170px;
      overflow: hidden;
 }

这是 fiddle JSFiddle

非常感谢

最佳答案

我尝试了一些东西,请告诉我这是否符合您的预期。 http://jsfiddle.net/z2p0r5s9/11/

<div id="effect" class="mores" style="background-color: brown">
<div class="panel">click
    <ul style="display:none">
        <li>Coffee</li>
        <li>Tea</li>
        <li>Milk</li>
    </ul>
</div>

CSS

.panel {
  width: 30px;
  height: 21px;
  overflow: hidden;
  color:white;
  background-color: grey;
  transition: all 2s ease;
}

JS

 var next_move = "expand";
 $(document).ready(function () {
 $(".panel").click(function () {
     console.log(next_move);
     var css = {};
     if (next_move == "expand") {
         css = {
             width: '210px',
             height: '170px'
         };
         next_move = "shrink";
          setTimeout(function(){
             $('ul').fadeIn();                 
         },2000);
     } else {
         css = {
             width: '30px',
             height: '20px'
         };
         console.log('hi');
         next_move = "expand";

     }
     $(this).animate(css, 200);
 });
});

关于javascript - 我如何对这个扩展了 onclick 的 div 使用缓动效果,以及对其中的元素淡入淡出效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26243827/

相关文章:

CSS 在 ie 中是错误的,而在 Chrome 中是正确的

javascript - 查找并显示重复值

javascript - 从子组件更新数组内的状态对象

html - 内框阴影 Div

javascript - 显示和隐藏 div onclick 按钮

javascript - 使 css 动画类在加载后重新加载

html - 如何垂直固定导航箭头?

javascript - Google Maps JavaScript API - fitbounds 与 setCenter

javascript - jQuery 插件检查版本

javascript - Jquery悬停与点击可扩展菜单