我有一个两栏的网站布局,其中左栏的内容是绝对的,右栏的div是固定的。我正在尝试获取它,以便当我向下滚动页面时,固定div框滚动经过锚点(在左侧),固定div的内容将发生变化(图像将被附加)。
到目前为止,我拥有的非常松散的编织jquery是:
(function ($) {
$(document).ready(function () {
var anchor = $("")
var code =
$(window).scroll(function (event) {
var y = $(this).scrollTop();
if (y >= anchor) {
$('#theDiv').append('<img id="livecodeimg" src="' + code +'.png" />')
} else {
$("#test img:last-child").remove()
}
});
});
})(jQuery);
我很难弄清楚变量是什么……
发布于 2012-06-17 00:43:51
您需要遍历每个a标记,并检查是否在滚动中传递了它。
(function ($) {
$(document).ready(function () {
var anchor = $("")
var code =
$(window).scroll(function (event) {
var y = $(this).scrollTop();
$('a').each(function() {
if (y >= $(this).offset.top) {
$('#theDiv').append('<img id="livecodeimg" src="' + code +'.png" />')
} else {
$("#test img:last-child").remove()
}
});
});
});
})
希望这能有所帮助。
https://stackoverflow.com/questions/11065096
复制相似问题