Bonjour,
Je navigue dans ma onepage avec ce plugin :
http://github.com/davist11/jQuery-One-Page-Nav

Le site est construit sur une page et la navigation se fait d'ancre en ancre.
La structure est la suivante :
  • - un bandeau fixe en haut,
  • - le bloc de navigation à gauche, en fixe également,
  • - le contenu central est divisé en section 1,2,3...


Je souhaiterai que le scroll s'arrête au niveau de chaque section et ne passe pas sous le bandeau fixe du haut.

J'ai essayé plusieurs possibilités sans succès. Je pense que cela vient du script jQuery, malheureusement je n'y connaît rien.
Pouvez-vous me dire s'il y a moyen de modifier un peu le jQuery ?

Merci infiniment par avance de regarder mon post.


Ci-dessous : le HTML (CSS inclus) et le script jQuery.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>TEST</title>
 
<style>
html, body {
	height: 100%; width: 100%;margin: 0; padding: 0}
 
#top {
	width: 100%;
	position: fixed;z-index:2;
	background-color: rgba(255,255,255, 0.6);
	border-bottom: 1px solid #000;
	height: 116px;
}
 
#page {
	position: relative;
	width: 100%;height: 100%;
	background-color: #c1f1c9;
	top: 116px;
}
#nav {
	position: fixed;
	width: 180px;
	height: 100%;
	left: 0; top:116px;z-index: 1;
}
#menu {
	margin:0;
	background-color: pink;}
 
.section {
	width: 900px;
	height: 100%;
	margin-left: 200px;
}
#section_1 {background-color: green;}
#section_2 {background-color: red;}
#section_3 {background-color: purple;}
#section_4 {background-color: grey;}
</style>
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="onepage.js"></script>
		<script>
			// NAVIGTATION dans la page
				$(document).ready(function() {
					$('#menu').onePageNav();
				});
		</script>
</head>
<body>
	<div id="top"></div>
 
	<div id="page">
		<nav id="nav">
			<ul id="menu">
				<li><a href="#section_1">SECTION 1</a></li>
				<li><a href="#section_2">SECTION 2</a></li>
				<li><a href="#section_3">SECTION 3</a></li>
				<li><a href="#section_4">SECTION 4</a></li>
			</ul>
		</nav>
 
		<section id="section_1" class="section">
		</section>
 
		<section id="section_2" class="section">
		</section>
 
		<section id="section_3" class="section">
		</section>
 
		<section id="section_4" class="section">
		</section>
	</div><!--Fin #page-->
 
</body>
</html>

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
 * jQuery One Page Nav Plugin
 * http://github.com/davist11/jQuery-One-Page-Nav
 *
 * Copyright (c) 2010 Trevor Davis (http://trevordavis.net)
 * Dual licensed under the MIT and GPL licenses.
 * Uses the same license as jQuery, see:
 * http://jquery.org/license
 *
 * @version 3.0.0
 *
 * Example usage:
 * $('#nav').onePageNav({
 *   currentClass: 'current',
 *   changeHash: false,
 *   scrollSpeed: 750
 * });
 */
 
;(function($, window, document, undefined){
 
	// our plugin constructor
	var OnePageNav = function(elem, options){
		this.elem = elem;
		this.$elem = $(elem);
		this.options = options;
		this.metadata = this.$elem.data('plugin-options');
		this.$win = $(window);
		this.sections = {};
		this.didScroll = false;
		this.$doc = $(document);
		this.docHeight = this.$doc.height();
	};
 
	// the plugin prototype
	OnePageNav.prototype = {
		defaults: {
			navItems: 'a',
			currentClass: 'current',
			changeHash: false,
			easing: 'swing',
			filter: '',
			scrollSpeed: 750,
			scrollThreshold: 0.5,
			begin: false,
			end: false,
			scrollChange: false
		},
 
		init: function() {
			// Introduce defaults that can be extended either
			// globally or using an object literal.
			this.config = $.extend({}, this.defaults, this.options, this.metadata);
 
			this.$nav = this.$elem.find(this.config.navItems);
 
			//Filter any links out of the nav
			if(this.config.filter !== '') {
				this.$nav = this.$nav.filter(this.config.filter);
			}
 
			//Handle clicks on the nav
			this.$nav.on('click.onePageNav', $.proxy(this.handleClick, this));
 
			//Get the section positions
			this.getPositions();
 
			//Handle scroll changes
			this.bindInterval();
 
			//Update the positions on resize too
			this.$win.on('resize.onePageNav', $.proxy(this.getPositions, this));
 
			return this;
		},
 
		adjustNav: function(self, $parent) {
			self.$elem.find('.' + self.config.currentClass).removeClass(self.config.currentClass);
			$parent.addClass(self.config.currentClass);
		},
 
		bindInterval: function() {
			var self = this;
			var docHeight;
 
			self.$win.on('scroll.onePageNav', function() {
				self.didScroll = true;
			});
 
			self.t = setInterval(function() {
				docHeight = self.$doc.height();
 
				//If it was scrolled
				if(self.didScroll) {
					self.didScroll = false;
					self.scrollChange();
				}
 
				//If the document height changes
				if(docHeight !== self.docHeight) {
					self.docHeight = docHeight;
					self.getPositions();
				}
			}, 250);
		},
 
		getHash: function($link) {
			return $link.attr('href').split('#')[1];
		},
 
		getPositions: function() {
			var self = this;
			var linkHref;
			var topPos;
			var $target;
 
			self.$nav.each(function() {
				linkHref = self.getHash($(this));
				$target = $('#' + linkHref);
 
				if($target.length) {
					topPos = $target.offset().top;
					self.sections[linkHref] = Math.round(topPos);
				}
			});
		},
 
		getSection: function(windowPos) {
			var returnValue = null;
			var windowHeight = Math.round(this.$win.height() * this.config.scrollThreshold);
 
			for(var section in this.sections) {
				if((this.sections[section] - windowHeight) < windowPos) {
					returnValue = section;
				}
			}
 
			return returnValue;
		},
 
		handleClick: function(e) {
			var self = this;
			var $link = $(e.currentTarget);
			var $parent = $link.parent();
			var newLoc = '#' + self.getHash($link);
 
			if(!$parent.hasClass(self.config.currentClass)) {
				//Start callback
				if(self.config.begin) {
					self.config.begin();
				}
 
				//Change the highlighted nav item
				self.adjustNav(self, $parent);
 
				//Removing the auto-adjust on scroll
				self.unbindInterval();
 
				//Scroll to the correct position
				self.scrollTo(newLoc, function() {
					//Do we need to change the hash?
					if(self.config.changeHash) {
						window.location.hash = newLoc;
					}
 
					//Add the auto-adjust on scroll back in
					self.bindInterval();
 
					//End callback
					if(self.config.end) {
						self.config.end();
					}
				});
			}
 
			e.preventDefault();
		},
 
		scrollChange: function() {
			var windowTop = this.$win.scrollTop();
			var position = this.getSection(windowTop);
			var $parent;
 
			//If the position is set
			if(position !== null) {
				$parent = this.$elem.find('a[href$="#' + position + '"]').parent();
 
				//If it's not already the current section
				if(!$parent.hasClass(this.config.currentClass)) {
					//Change the highlighted nav item
					this.adjustNav(this, $parent);
 
					//If there is a scrollChange callback
					if(this.config.scrollChange) {
						this.config.scrollChange($parent);
					}
				}
			}
		},
 
		scrollTo: function(target, callback) {
			var offset = $(target).offset().top;
 
			$('html, body').animate({
				scrollTop: offset
			}, this.config.scrollSpeed, this.config.easing, callback);
		},
 
		unbindInterval: function() {
			clearInterval(this.t);
			this.$win.unbind('scroll.onePageNav');
		}
	};
 
	OnePageNav.defaults = OnePageNav.prototype.defaults;
 
	$.fn.onePageNav = function(options) {
		return this.each(function() {
			new OnePageNav(this, options).init();
		});
	};
 
})( jQuery, window , document );