我正在尝试使用 jQuery 中的 .on() 来捕获标签内的滚动事件.
I'm attempting to use the .on() from jQuery to catch a scroll event that is inside a tag.
所以这是我的解决方案:
so this was my solution:
getScrollTop() 是一个返回顶部值的javascript函数(有效)
getScrollTop() is a javascript function to return the top value (works)
$(document).on("scroll#popup", '#popup', function(){
alert('scrolling');
$(".fixedHeader").css("position", "relative");
$(".fixedHeader").css("top", getScrollTop());
});
事件只是scroll,而不是scroll#popup.
// http://ejohn.org/blog/learning-from-twitter
// Also, be consistent with " vs '
var $fixedHeader = $('.fixedHeader').css('position', 'relative');
$(document).on('scroll', '#popup', function() {
console.log('scrolling'); // you *really* don't want to alert in a scroll
$fixedHeader.css("top", getScrollTop());
});
这篇关于如何使用 JQuery .on() 捕捉滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
用于创建头像的 jQuery/JavaScript 库?jQuery/JavaScript Library for avatar creation?(用于创建头像的 jQuery/JavaScript 库?)
如何做以下掩码输入问题?How to do following mask input problem?(如何做以下掩码输入问题?)
使用 DropKick Javascript 设置值/标签的问题Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 设置值/标签的问题)
如何对 jquery 插件中的私有方法进行单元测试?how to unit-test private methods in jquery plugins?(如何对 jquery 插件中的私有方法进行单元测试?)
stellar.js - 为垂直滚动网站配置偏移量/对齐元素stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 为垂直滚动网站配置偏移量/对齐元素?)
jQuery 屏蔽输入插件.当文本框获得焦点时选择所有jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽输入插件.当文本框获得焦点时选择所有内容)