覆盖/替换jquery点击功能

时间:2020-06-05 11:33:29

标签: html jquery jquery-animate

如果这是一个明显的问题,请原谅我。

我正在使用无法删除或更改的脚本来处理页面。单击一个按钮,该按钮会通过ajax请求将某些项目加载到页面上,然后触发该页面的烦人的卷轴动画。

目标:我仍然希望在单击按钮时加载项目,但我不希望滚动动画。

我可以在页面上添加我自己的自定义js(在添加默认脚本的下面)。如何中断或覆盖原始脚本以删除滚动行为?

这是一个简化的示例。

.group{
	background: cyan;
	height:400px;
	width:400px;
	margin:10px
}
.load-more{
	background:#88f;
	width:360px;
	text-align:center;
	margin:10px;
	padding:20px;
  cursor:pointer;
}
<!-- markup -->
<div class="groups-listing">
	<div class="group"></div>
</div>
<div class="load-more">Load more</div>

<!-- scripts -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
	$(".load-more").click(function () {
		//loading another item
		$(".groups-listing").append('<div class="group"></div>');
		
		//annoying animated scrolling
		$("html, body").animate(
			{
				scrollTop: $(".groups-listing .group").last().offset().top
			},2000
		);
	});
</script>
<script>
  // custom js, override must go here.
</script>

实际问题可以在这里找到:https://obsu.unionclouduat.org/groups 我认为我的简化示例很模糊,但我不确定100%。

1 个答案:

答案 0 :(得分:1)

您可以尝试unbind()并重新分配活动吗?

// custom js, override must go here.

$(".load-more").unbind().click(function () {
        //loading another item
        $(".groups-listing").append('<div class="group"></div>');
});
相关问题