jquery - jquery $(document).on("scroll") 禁用
问题描述
到目前为止,我已经构建了一个在滚动时将 html 元素粘贴到页面顶部的函数,但我想在其中创建一个函数来销毁每个指定元素的 $(document).on("scroll")。有人可以帮我实现这一目标吗?到目前为止,我的代码是:
$(element).each(function() {
var default_settings = {
parent: null,
offsetTop: 0,
offsetBottom: 0,
fixBottom: true
};
var elm = $(this),
parent = $(settings.parent);
var elmTop = elm.offset().top,
elmLeft = elm.offset().left,
elmWidth = elm.width(),
elmHeight = elm.height(),
parentTop = parent.offset().top,
parentHeight = parent.outerHeight(true),
offs = elmTop - settings.offsetTop,
margin_top = elmTop - parentTop,
margin_bottom = parentHeight - elmHeight - margin_top,
diff = parentHeight - elmHeight + parentTop - settings.offsetTop - settings.offsetBottom;
$(document).on("scroll", function(){
var w_top = $(window).scrollTop();
if(w_top > offs && w_top < diff) {
elm.attr("style", "position: fixed; top: "+settings.offsetTop+"px; left: "+elmLeft+"px; margin-left: 0;");
if(!elm.next('[data-sticket-controller]').length) {
elm.after('<div data-sticket-controller style="visibility: hidden; opacity: 0; position: relative; width: '+elmWidth+'px; height: '+elmHeight+'px;"></div>');
}
}
else if(w_top >= diff) {
if(settings.fixBottom) {
elm.attr("style", "position: absolute; bottom: "+settings.offsetBottom+"px; left: "+elmLeft+"px; margin-left: 0;");
}
}
else {
elm.removeAttr("style");
elm.next("[data-sticket-controller]").remove();
}
}
});
});
解决方案
推荐阅读
- coq - 在 Coq 中生成一个函数,将每个证人输出到一个存在唯一性公理
- python - 如何将日期转换为 json 序列化?
- python - Python Selenium ConnectionRefusedError: [WinError 10061] 无法建立连接,因为目标机器主动拒绝了它
- reactjs - 单行 ApexCharts 的多个 y 轴标签
- java - 使用并行化时在可重用功能上调用 Java 函数时出错
- python - 将 DataFrame 分组并绘制它
- javascript - 数组每次循环时都会重复
- arrays - 在 VB.NET 中获取两个数组元素的平均值
- android - Android Studio gradle 不显示运行配置
- android - 此版本不符合 Google Play 64 位要求(Apple Music Kit)