【发布时间】:2013-09-14 08:24:01
【问题描述】:
我的 SharePoint 页面生成了这个 HTML(已剪辑):
<body scroll="yes" onload="if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();" class="v4master" style="overflow: scroll" spellcheck="false">
<form name="aspnetForm" method="post" action="/Lists/List/EditNewForm.aspx?ID=2&Source=https%3A%2F%2Fsp2010-test%2Eatwss%2Ecom%2FLists%2FList%2FAllItems%2Easpx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" style="overflow: scroll">
// some html here
<div id="competenceTotalSum" style="position: absolute; left: 500px; top: 400px; width: 100px; height: 50px; background-color:gray" />
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("form#aspnetForm").bind("scroll", function(e){
alert("scroll");
$("#competenceTotalSum").css("top", $(this).scrollTop() + 400);
});
});
</script>
// some html here
</form>
</body>
事件scroll 未触发。我更改了body 的scroll 属性,body 和form 的溢出属性,尝试将scroll 事件绑定到不同的对象(window、body、form)。当将 scroll 事件更改为 click 事件时 - 它会触发。除了滚动元素的overflow 属性,我没有找到任何原因。
【问题讨论】:
-
bind() 已被弃用,取而代之的是“on” - 请参阅此处:api.jquery.com/on
-
@Sebastian,谢谢,但它没有解决问题。使用 on() 它也不起作用。
-
抱歉给您带来了困惑——上面的评论只是对您的代码的一般建议。有关实际答案,请参阅下面的答案。 ;)
-
@Sebastian,这两个答案都没有帮助我。出于我的目的,我使用了 $(window).resize 事件和块的固定位置。
标签: javascript jquery html sharepoint scroll