javascript - JQuery动画div从右到左平滑

标签 javascript jquery html css css-transitions

我创建了页面,一开始它会显示黑屏,主屏幕从右到左可见,我尝试使用 jQuery animate 实现,它似乎工作正常但没有平滑度.我尝试使用 CSS 过渡,但没有成功

有人可以建议如何增加平滑度,向左推的屏幕应该平滑且缓慢

这是 JSfiddle Example

编辑 我制作了一个视频来展示它在我的电脑中的显示方式:

https://www.youtube.com/watch?v=yvfxI84Bzt4&feature=youtu.be

谢谢

var winw = $(window).width();
var winh = $(window).height();
var main = $('.mc-root');

$(main).animate({ right: '0' }, 900 );
body {
  margin: 0;
  padding: 0;
  background-color: #000;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
}
.main-outer {
  position: absolute;
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
.mc-root {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  -webkit-transition: all 2s linear;
  transition: all 3s linear;
  right:-100%;
  
}
.leftcol {
  width: 130px;
  height: 100%;
  background: #fff;
  position: absolute;
  left: 0;
  top: 0;
}
.leftcol > p {
  margin: 50px 0 0 0;
  text-align: center;
}
.rightcol {
  width: calc(100% - 130px);
  background: #666;
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
}
.rightcol > p {
  margin: 50px 0 0 0;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main-outer">
  <div class="mc-root">
    <div class="leftcol">
      <p>NAV</p>
    </div>
    <div class="rightcol">
      <p>MAIN Content</p>
    </div>
  </div>
</div>

最佳答案

这里,我觉得比较流畅,关键在于时间和持续时间,

如果你觉得我的解决方案不够流畅,你可以改变功能或时长

var winw = $(window).width();
var winh = $(window).height();
var main = $('.mc-root');

$(main).animate({ right: '0' }, 900 );
body {
  margin: 0;
  padding: 0;
  background-color: #000;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
}
.main-outer {
  position: absolute;
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
}
.mc-root {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  -webkit-transition: all 2s ease-in-out;
  transition: all 2s ease-in-out;
  right:-100%;
  
}
.leftcol {
  width: 130px;
  height: 100%;
  background: #fff;
  position: absolute;
  left: 0;
  top: 0;
}
.leftcol > p {
  margin: 50px 0 0 0;
  text-align: center;
}
.rightcol {
  width: calc(100% - 130px);
  background: #666;
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
}
.rightcol > p {
  margin: 50px 0 0 0;
  text-align: center;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main-outer">
  <div class="mc-root">
    <div class="leftcol">
      <p>NAV</p>
    </div>
    <div class="rightcol">
      <p>MAIN Content</p>
    </div>
  </div>
</div>

关于javascript - JQuery动画div从右到左平滑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44135524/

相关文章:

JavaScript stopImmediatePropagation 在事件处理程序中不起作用

javascript - 自执行函数作为javascript中的对象属性值

javascript - 动态添加单选按钮

javascript - 我们可以在 setInterval 函数中自动暂停 animate() 和resume() 吗?

javascript - DataTable() 没有给出正确的对象引用

javascript - 使用 Javascript 通过 AJAX 数据动态生成表

Javascript:将数组转换为 CSV 格式并复制到剪贴板

javascript - 在输出数据之前等待循环完成每个数组项的 $.getJSON

html - 使用对象标签在 html 中显示内联 pdf

html - 制作一个 div "hug"它包含的组件