- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在页面顶部实现 Logo 面板的简单动画,当滚动超过某个点时缩放,如果向上滚动则向上缩放。我使用 jquery 的 .animate()
函数来更改一些 css 参数。我还使用 .stop()
函数来中断滚动监听器,这样整个动画就不会出现延迟。
快完成了,但我注意到在动画播放过程中出现了一些不稳定的延迟。例如,当我向下滚动时,它会缩小,但不会一直缩小,只是稍微缩小,然后在一秒钟内跳到完全缩小的位置。向上滚动时也会发生同样的情况——它会在中途缩放,甚至会在向上滚动之前稍微暂停几次。您认为是什么原因造成的?
这是我的代码:
(function($) {
$(document).ready(function() {
var animScroll;
$(window).scroll(function() {
if ($(this).scrollTop() > 700) {
animScroll = true;
$('#menu').stop().animate({height: '50px'}, {
queue: false,
duration: 400
});
$('#toplogo').stop().animate({width: '150px'}, {
queue: false,
duration: 400
});
} else if ($(this).scrollTop() < 700) {
$('#menu').stop().animate({height: '85px'}, {
queue: false,
duration: 400
});
$('#toplogo').stop().animate({width: '300px'}, {
queue: false,
duration: 400
});
}
});
});
})(jQuery);
最佳答案
就动画而言,JQuery 并不是最快的。下面我使用了 CSS。请注意我将翻转点更改为 300 像素。
(function($) {
$(document).ready(function() {
var animScroll;
$(window).scroll(function() {
if ($(this).scrollTop() > 300) {
$('#toplogo').addClass("smaller");
} else if ($(this).scrollTop() < 300) {
$('#toplogo').removeClass("smaller");
}
});
});
})(jQuery);
.container {
height: 1000px;
}
#menu {
position: fixed;
top: 0;
}
#toplogo {
transition: all .2s ease-in-out;
}
#toplogo.smaller {
transform: scale(0.5, 0.5);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<div id="menu">
<img id="toplogo" src="http://placehold.it/200">
</div>
</div>
关于滚动上的 jquery 生涩动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45417970/
大家好,我使用的是翻译动画,如下所示: 现在它工作正常,除了它在动画时似乎闪烁/ SCSS ?这是标准吗? 我确实有 6 个不同的 View 同时被激活,这是原因吗? 这是我设置动画的方式: //
我正在将我的表格从 XML 提要加载到数组中,然后创建单元格,如下面的代码所示。加载时有时会非常不稳定。我以为那只是我滚动时下载的图像,但我删除了它们进行测试,有时它仍然不稳定。无法弄清楚我做错了什么
我一直在使用 scale() 属性,直到几周前它都运行良好。浏览器更新后,现在我看到一个不稳定/跳跃的动画,有人可以指出我的问题到底出在哪里吗? 请看下面的 jsFiddle ;在翻转中,ICON(显
这是网站 --> http://giantsofafrica.org/camps/top-50-camp/ 每当我在这个网站上使用 fancybox 时,都会出现这种奇怪的、不稳定的、滑动的 Acti
我正在使用 XMLParser 为 ListView 获取带有日期的 XML。解析器将日期发送到 LazyAdapter,然后由 LazyAdapter 构建列表。 当我在我的应用程序中滚动时,Lis
我正在尝试将图像动画化到 Canvas 上。 在 html 文件中我有 dog.png,它是一个 Image Sprites。 在 CSS 文件中: #dog{ object-positio
我正在尝试使用 Bootstrap 4 从我的导航中获得一个很好的幻灯片,但它真的很生涩。这是我的代码: var videoWidth = 1280; var video = $(".vid
我有一个 UITableView,其中包含多个带有标题的部分,可折叠/展开。还有一个带有自定义 UIView 的 tableHeaderView。 使用自定义部分标题 UIView 和自定义 UITa
在我的 vmware、主机 linux 上安装 maverick 后,鼠标不稳定,我该如何解决? 最佳答案 这是我尝试过的累积解决方案,我认为更新 VMWARE 工具对我有用。 可能的解决方案:1.
我在使用 UITableView 时遇到了这个问题,tableView 的 cells 高度不同,自动布局约束设置不当。当您向下滚动到 tableView 的底部并加载更多数据(无论使用 reload
我在 GLSurfaceView 上使用 GLES 2.0 用 Java 制作了一个小型 2D 游戏。但我在性能方面遇到了一些问题。我在 OnDrawFrame 函数中完成了所有游戏状态的渲染和更
我是一名优秀的程序员,十分优秀!