我目前有一个类似议程的应用程序,其中第一列绝对水平,第一行绝对垂直。我通过捕获滚动效果并更改其附加的 CSS 类的 left 或 top 属性来实现此目的。 (这些课程最多可达 700 个项目(每天 2 年))。
$(window).scroll(function () {
$('.Planning tr > td:first-child').css("left", "" + $(this).scrollLeft() + "px");
$('.Planning thead > tr:first-child').css("top", $(this).scrollTop()+50 + "px");
});
这在所有浏览器中都按预期工作(我在 Chrome、Firefox 和 Internet Explorer 中进行了测试)
但在 Internet Explorer 上,速度非常慢。
滚动仅在停止滚动后显示,而在 Chrome 和 Firefox 中,顶行看起来是固定的,这看起来更好,更用户友好。
有什么办法可以增强这个吗?或者有任何针对 Internet Explorer 进行优化的库,以便我可以避免 IE 中的这种“缓慢”行为?
https://jsfiddle.net/7mfcrLh5/12/对于 jsfiddle 示例(这在 Chrome 中效果很好,但在 Internet Explorer 中则不然)
你可以尝试throttle每 100 毫秒或 200 毫秒滚动一次的功能,每秒仍然相当快。
var planningCol = $('.Planning tr > td:first-child'),
planningHead = $('.Planning thead > tr:first-child');
$(window).scroll(function(){
var self = this;
throttle(function(){
planningCol.css({ left: $(self).scrollLeft() });
planningHead.css('top', $(self).scrollTop() + 50 + 'px');
}(), 200); // call your function directly upon return
});
或者你可以在 body 上使用 CSS,检测页面何时scrolled
or scrolling
。然后申请.scrolling { pointer-events: none !important; }
这增强了用户界面。
如果选择始终相同,也请尝试将选择移出滚动功能。
var win = $(window),
body = $(document.body),
planning = $('.Planning'),
planningCol = planning.find('tr > td').first(),
planningHead = planning.find('thead > tr').first();
win.scroll(function(){
// scrolled
body.toggleClass('scrolled', !!win.scrollTop());
// scrolling
body.addClass('scrolling');
planningCol.css({ left: win.scrollLeft() });
planningHead.css({ top: win.scrollTop() });
setTimeout(function(){
body.removeClass('scrolling');
}, 200);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)