如何在不知道锚点名称的情况下使链接转到页面上的下一个锚点? [英] How can I make a link go to the next anchor on the page without knowing anchor name?

查看:124
本文介绍了如何在不知道锚点名称的情况下使链接转到页面上的下一个锚点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面顶部有一个按钮,无论它是什么,我都希望对其进行编码以转到下一个锚点.实际上,我将要执行下一个/上一个按钮以转到下一个和上一个锚点.此按钮位于静态框架上,因此它应该理想地滚动页面的其余部分.

I have a button at the top of the page, and I want to code it to proceed to the next anchor regardless of what it is. Actually I will want to do next / previous buttons to go to next and previous anchors. This button is on a static frame so it should scroll the rest of the page ideally.

任何建议都会很棒.再次,我不知道锚点是什么,这更像是使用通用按钮的章节导航.

Any suggestions would be great. Again I won't know what the anchor is, this is more like a chapter navigation using a generic button.

好像在dom中找到下一个锚对象,然后去做应该是一件可行的事情,但是我并不是jquery或javascript中的专家.

Seems like finding next anchor object in the dom and go there should be a doable thing but I'm not a whiz in jquery or javascript to do that.

推荐答案

var index = -1;

$('.next').click(function() {
   index++;
   $(window).scrollTop($('a').eq(index).position().top);

});
$('.previous').click(function() {
   index--;
   if(index < 0) { index = 0;}

   $(window).scrollTop($('a').eq(index).position().top);
});

这篇关于如何在不知道锚点名称的情况下使链接转到页面上的下一个锚点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆