javascript - jquery 侧边导航在移动设备上不流畅

标签 javascript jquery html css web

我用 Jquery 制作的侧边导航有问题,它在笔记本电脑或台式机上运行良好,但在移动设备上,转换不像在台式机或笔记本电脑上那样流畅 我不知道是什么导致了这个问题

如果你想知道我通过切换一个从左侧占据侧边导航位置的类来实现侧边导航:-30%;到 30%

最佳答案

我真的很想向您展示性能上的差异。查看我的演示。单击一个框以查看它的移动。即使在我的新 MacBook Air 上,我也能分辨出不同之处。正如您所注意到的,在移动设备上,差异更为明显。

$(".box").on("click", function() {
  $(this).addClass("start");
})

$(".reset").on("click", function() {
  $(".box").removeClass("start");
})
@keyframes moveWithLeft {
  from {
    left: 0; 
  }
  to {
    left: calc(100vw - var(--box-width));
  }
}

@keyframes moveWithTransform {
  to {
    transform: translate(calc(100vw - var(--box-width)));
  }
}

.box {
  --box-width: 80px;
  --box-height: 70px;  
  width: var(--box-width);
  height: var(--box-height);
  line-height: var(--box-height);  
  background-color: rgba(0, 128, 0, 1);
  position: absolute;
  color: white;
  display: inline-block;
  cursor: pointer;
  font-family: helvetica;
  transition: 0.3s background-color ease-in-out;
}

.box:hover {
  background-color: rgba(0, 128, 0, .8);
}

.box span {
  text-align: center;
  display:  block;
  font-size: 85%;
}

.box.two {
  top: calc(var(--box-height) + 5px);
}

.one.start {
  animation: 3s moveWithLeft forwards; 
}

.two.start {
  animation: 3s moveWithTransform forwards; 
}

button {
  position: fixed;
  bottom: 0;
  left: 0;
  font-size: 1.2rem;
  font-family: helvetica;
  padding: 10px;
  border: none;
}


html, body {
  margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="box one"><span>Left</span></div>
<div class="box two"><span>Transform</span></div>

<button class="reset">Reset</button>

jsFiddle

关于javascript - jquery 侧边导航在移动设备上不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55076558/

相关文章:

javascript - jQuery - 错误 : unsupported pseudo: visible

javascript - 使用adobe air和javascript在sqlite db中插入日期

jquery - 如何使用 idref 解析 xml 元素

javascript - 从移动服务数据源的 ListView 中获取值(value)

html - block 格式化上下文、折叠边距和 float 容器

php - 更改 HTML 源文件相对路径的 src 路径

javascript - 如何使用字符串测试 JS 库是否已加载

javascript - Angular ui 路由器仅传递来自 $http get 的数据

javascript - 单击任何项​​目时显示菜单项

javascript - 在 jquery 中继器的 div 中附加图像