Html JQuery-延迟函数
我有一个功能,根据滚动/调整大小/加载上的其他元素(包括固定标题),将侧导航定位到固定位置。顶部位置在内容容器旁边(#timelineFulltext)或标题(.sticky)下方计算 问题是位置在粘性标题隐藏之前开始,这是另一个功能Html JQuery-延迟函数,html,jquery,Html,Jquery,我有一个功能,根据滚动/调整大小/加载上的其他元素(包括固定标题),将侧导航定位到固定位置。顶部位置在内容容器旁边(#timelineFulltext)或标题(.sticky)下方计算 问题是位置在粘性标题隐藏之前开始,这是另一个功能 jQuery(window).on('load scroll resize',function() { setTimeout(function() { // Position TOC on load, scroll and r
jQuery(window).on('load scroll resize',function() {
setTimeout(function() {
// Position TOC on load, scroll and resize
var isSticky = jQuery('.sticky'); // Check if sticky header is present
if(isSticky.length && jQuery('#timelineFulltext').offset().top < jQuery(window).scrollTop()){
var timelinePosition = isSticky.height() + 38;
}
else{
var timelinePosition = jQuery('#timelineFulltext').offset().top - jQuery(window).scrollTop();
}
jQuery('.fixed-timeline').css({'top': timelinePosition + 'px'});
},
3000);
});
是否有办法延迟此功能的执行:
jQuery(window).on('load scroll resize', function (){
// Position TOC on load, scroll and resize
var isSticky = jQuery('.sticky'); // Check if sticky header is present
if(isSticky.length && jQuery('#timelineFulltext').offset().top < jQuery(window).scrollTop()){
var timelinePosition = isSticky.height() + 38;
}
else{
var timelinePosition = jQuery('#timelineFulltext').offset().top - jQuery(window).scrollTop();
}
jQuery('.fixed-timeline').css({'top': timelinePosition + 'px'});
});
jQuery(窗口).on('load scroll resize',函数(){
//加载时定位TOC,滚动并调整大小
var isSticky=jQuery('.sticky');//检查是否存在sticky头
if(isSticky.length&&jQuery('#timelineFulltext').offset().top
解决方案是使用设置超时时间。在本例中,它将在执行函数之前等待3秒钟
jQuery(window).on('load scroll resize',function() {
setTimeout(function() {
// Position TOC on load, scroll and resize
var isSticky = jQuery('.sticky'); // Check if sticky header is present
if(isSticky.length && jQuery('#timelineFulltext').offset().top < jQuery(window).scrollTop()){
var timelinePosition = isSticky.height() + 38;
}
else{
var timelinePosition = jQuery('#timelineFulltext').offset().top - jQuery(window).scrollTop();
}
jQuery('.fixed-timeline').css({'top': timelinePosition + 'px'});
},
3000);
});
jQuery(窗口).on('load scroll resize',function(){
setTimeout(函数(){
//加载时定位TOC,滚动并调整大小
var isSticky=jQuery('.sticky');//检查是否存在sticky头
if(isSticky.length&&jQuery('#timelineFulltext').offset().top
您可以创建一个函数,比如说hideStickyBar
来应用标题粘滞条脚本。从jquery中的hide
函数调用此函数作为回调。请参见下面的示例代码
$('#elementTohide').hide(400, hideStickyBar);
jQuery(window).on('load scroll resize', function (){
hideStickyBar();
});
function hideStickyBar() {
// Position TOC on load, scroll and resize
var isSticky = jQuery('.sticky'); // Check if sticky header is present
if(isSticky.length && jQuery('#timelineFulltext').offset().top < jQuery(window).scrollTop()){
var timelinePosition = isSticky.height() + 38;
}
else{
var timelinePosition = jQuery('#timelineFulltext').offset().top - jQuery(window).scrollTop();
}
jQuery('.fixed-timeline').css({'top': timelinePosition + 'px'});
}
$('#elementTohide').hide(400,hideStickyBar);
jQuery(窗口).on('load scroll resize',函数(){
hideStickyBar();
});
函数hideStickyBar(){
//加载时定位TOC,滚动并调整大小
var isSticky=jQuery('.sticky');//检查是否存在sticky头
if(isSticky.length&&jQuery('#timelineFulltext').offset().top
您可以在隐藏标题后调用sticky header函数这听起来很有希望^您能给我举个例子吗?