我在 AMP 页面中创建了排序功能,现在当我请求对结果进行排序时,以及当我在成功提交表单后更新状态时,页面滚动位置保持不变。我希望每当排序完成后更新状态时页面都会滚动到顶部。
这是我的代码:
<form method="GET"
action="http://localhost:3001/api/v2/<%=@taxonomy%>/<%=@taxon%>"
action-xhr="http://localhost:3001/api/v2/<%=@taxonomy%>/<%=@taxon%>"
target="_top"
on="submit-success: AMP.setState({
product_list: {
detail: event.response.detail
}
}),sort_lb.close();">
<input type="hidden" name="sort" value="pop">
<input type="submit" value="Popularity" class="sort_submit_btn">
</form>
放置一个html代码<span id="ANY_ID"></span>
添加动作和事件:ANY_ID.scrollTo()
在你的情况下:
on="submit-success: AMP.setState({
product_list: {
detail: event.response.detail
}
}),YOUR_ID.scrollTo(),sort_lb.close();">
灯箱关闭的示例:点击此处查看 https://codepen.io/bachchasingh/pen/NEwXyP
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)