当页面太长时,会导致浏览不便,这时就需要一个页面锚点菜单(Page Scroll Menu),方便用户快速了解页面的概要及目录并快速定位到相应的目录。

实现方式:

1. 将页面按照内容分成不同的Section, 页面加载时读取各个Section并生成Menu,点击对应的Menu时计算对应Section的位置并设置其位置。

示例 1:http://www.outyear.co.uk/smint/, http://www.outyear.co.uk/smint/demo/

示例 2:http://manos.malihu.gr/page-scroll-to-id

2.  在页面中根据内容插入A标签,定义锚点,在页面加载时收集这些锚点并生成Menu,点击Menu时直接跳转到相应的锚点。

示例 1: http://sympies.com/pagescroll_jquery_menu/

示例 2:HPEMEA项目中的Author模块,主要代码摘录如下:

(function () {
if (window.SideAnchorMenu == undefined) {
window.SideAnchorMenu = function () {
this.isInited = false;
};
} SideAnchorMenu.prototype.init = function (showTop, forceInit) {
if (forceInit === false && this.isInited) return;
var anchorMenu;
if ($("#divSideAnchorMenu").size() == 0) {
if (showTop) {
anchorMenu = $("<div><img src='/Modules/Aximpro.DotNetValue.Anchor/Content/Images/axLogo.png' alt='axLogo' id='axlogo' /><br/><hr id='logo-separator'><br/></div><div><ul><li><a href='#'><span></span><div>Top</div></a></li></ul></div>");
}
else {
anchorMenu = $("<div><img src='/Modules/Aximpro.DotNetValue.Anchor/Content/Images/axLogo.png' alt='axLogo' id='axlogo'/><hr id='logo-separator'></div><div><ul></ul></div>");
}
anchorMenu.attr("id", "divSideAnchorMenu");
$("body").append(anchorMenu);
} else {
anchorMenu = $("#divSideAnchorMenu");
anchorMenu.find("ul").empty();
}
var $ul = anchorMenu.find("ul");
var eventHandler = {
anchorMenuItemClick: function () {
$ul.find("li").removeClass("active");
$(this).addClass("active");
},
windowScollHandler: function () {
$ul.find("li").removeClass("active");
var windowScrollTop = $(this).scrollTop();
var windowHeight = $(window).height();
var forcedLi;
$(".anchorMark").each(function () {
var anchorOffsetTop = $(this).offset().top;
if (anchorOffsetTop <= windowScrollTop + windowHeight/3) {
forcedLi = $ul.find("a[href='#" + $(this).attr("id") + "']").parent();
var bgImage = document.body.style.backgroundImage
if (document.body.style.backgroundImage.toString().indexOf($(this).attr("id") + ".jpg", 0) == -1) { document.body.style.background = "url(/Skins/Single_Page/1.0/backgrounds/" + $(this).attr("id") + ".jpg) no-repeat center center fixed";
document.body.style.backgroundSize = "cover";
}
}
}); if (forcedLi) {
forcedLi.addClass("active");
} else {
$ul.find("a[href='#']").parent().addClass("active");
}
}
}; $(".anchorMark").each(function (i, item) {
var $item = $(item);
var anchor = $("<a><span></span><div></div></a>");
anchor.attr("href", "#" + $item.attr("id"));
anchor.attr("class", 'anchor-item');
anchor.find("div").text($item.attr("title"));
var $li = $("<li></li>");
$li.append(anchor);
$ul.append($li);
$li.click(eventHandler.anchorMenuItemClick);
});
//$ul.pagescroll_menu({ "position": "right", "fontfamily": "Forum" }); $(window).scroll(eventHandler.windowScollHandler);
this.isInited = true;
};
<!--//--><![CDATA[//><!--
$(document).ready(function () { $('a[href*=#]:not([href=#])').click(function () {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 150 }, 800); return false;
}
}
}); if (window.SideAnchorMenuInstance == undefined) {
window.SideAnchorMenuInstance = new window.SideAnchorMenu();
window.SideAnchorMenuInstance.init(false);
}
});
//--><!]]>
})();

Page Scroll Menu (页面中锚点菜单)的更多相关文章

  1. 回发或回调参数无效。在配置中使用 pages enableEventValidation=true 或在页面中使用 %@ Page EnableEventValidation=true % 启用了事件验证

    WebForm中回发或回调参数无效问题的解决 解决 .NET中回发或回调参数无效问题的解 该错误的详细提示信息为: 回发或回调参数无效.在配置中使用 <pages enableEventVali ...

  2. Page Scroll Effects - 简单的页面滚动效果

    Codyhouse 收集了一组页面滚动效果,就是目前大家很常见的用户在浏览网页的时候.一些效果虽然极端,但如果你的目标是创建一个身临其境的用户体验,他们是非常有用的.所有的动画都使用 Velocity ...

  3. 从下拉菜单拖拽一个元素 出来,插入到页面中的app 列表中

    1,实现功能:从下拉菜单拖拽一个元素 出来,插入到页面中的app 列表中 并实现app向后移动一个元素的位置: 2.实现思路: 01.遍历下拉菜单,添加拖拽方法,实现位置移动功能: 02.遍历app列 ...

  4. 回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。

    问题补充: “/Source”应用程序中的服务器错误. 回发或回调参数无效.在配置中使用 <pages enableEventValidation="true"/> 或 ...

  5. Jsp页面中常见的page指令

    注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6513327323628962312/ 1.<JSP页面实际上就是Servlet> 2.<JSP页 ...

  6. 前端开发css实战:使用css制作网页中的多级菜单

    前端开发css实战:使用css制作网页中的多级菜单 在日常工作中,大家都会遇到一些显示隐藏类菜单,比如页头导航.二维码显示隐藏.文本提示等等......而这些效果都是可以使用纯css实现的(而且非常简 ...

  7. jsp页面中引用其他页面的方法

    初看这个标题....大家的感觉一定是好2啊.....博主一定要说jsp的动态引用(jsp:include)和静态引用(@include)了.介绍这两者区别的文章已经烂大街了..一搜一大把..博主竟然还 ...

  8. HTML页面中常见的一些小方法

    在<Head>标签中加   <meta http-equiv="pragma " content="no-cache"> <met ...

  9. JQuery 根据ID在页面中定位

    1.锚点跳转简介 锚点其实就是可以让页面定位到某个位置上的点.在高度较高的页面中经常见到.比如百度的百科页面,wiki中的page内容. 我知道实现锚点的跳转有两种形式,一种是a标签+name属性:还 ...

随机推荐

  1. 判断线段相交 -- 51nod 1264 线段相交

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1264 三角形的有向面积:a.x*b.y+b.x*c.y+c.x*a.y ...

  2. BZOJ 2038 小Z的袜子(hose)(分组)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2038 题意:给出n个袜子.m个询问,每个询问一个区间[L,R],询问这个区间中任意拿出两 ...

  3. Order to Cash Process

    order to cash process steps can be listed as below · Enter the Sales Order · Book the Sales Order · ...

  4. R语言算术运算和逻辑运算

    Arithmetic Operators Operator Description + addition - subtraction * multiplication / division ^ or ...

  5. [HDOJ5573]Binary Tree(找规律,贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5573 这个题……规律暂时还找不到,先贡献两发TLE的代码吧,一个dfs一个状压枚举. #include ...

  6. string中常用的函数

    string中常用的函数 发现在string在处理这符串是很好用,就找了一篇文章放在这里了.. 用 string来代替char * 数组,使用sort排序算法来排序,用unique 函数来去重1.De ...

  7. minimum-moves-to-equal-array-elements

    https://leetcode.com/problems/minimum-moves-to-equal-array-elements/ package com.company; import jav ...

  8. ssh传输出现encountered 1 errors during the transfer解决办法

    以下方法简单排序,从简单到复杂: 法一:在SSH Secure File Transfer(上传文件那个),打开“Operation”菜单,打开“File Transfer Mode”子菜单,再选择“ ...

  9. css新增UI样式

    1.圆角 border-radius <style> .box{width:200px;height:300px;border:1px solid #000;border-radius:1 ...

  10. linux shared lib 使用与编译

    一.              动态链接库的原理及使用 Linux提供4个库函数.一个头文件dlfcn.h以及两个共享库(静态库libdl.a和动态库libdl.so)支持动态链接. Ø        ...