Subversion Repositories Sites.obs-saisons.fr

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
40 aurelien 1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
	<meta charset="UTF-8" />
5
	<title>jQuery UI Slider - Slider scrollbar</title>
6
	<link type="text/css" href="../../themes/base/jquery.ui.all.css" rel="stylesheet" />
7
	<script type="text/javascript" src="../../jquery-1.4.2.js"></script>
8
	<script type="text/javascript" src="../../ui/jquery.ui.core.js"></script>
9
	<script type="text/javascript" src="../../ui/jquery.ui.widget.js"></script>
10
	<script type="text/javascript" src="../../ui/jquery.ui.mouse.js"></script>
11
	<script type="text/javascript" src="../../ui/jquery.ui.slider.js"></script>
12
	<link type="text/css" href="../demos.css" rel="stylesheet" />
13
	<style type="text/css">
14
		#demo-frame > div.demo { padding: 10px !important; }
15
		.scroll-pane { overflow: auto; width: 99%; float:left; }
16
		.scroll-content { width: 2440px; float: left; }
17
		.scroll-content-item { width: 100px; height: 100px; float: left; margin: 10px; font-size: 3em; line-height: 96px; text-align: center; }
18
		* html .scroll-content-item { display: inline; } /* IE6 float double margin bug */
19
		.scroll-bar-wrap { clear: left; padding: 0 4px 0 2px; margin: 0 -1px -1px -1px; }
20
		.scroll-bar-wrap .ui-slider { background: none; border:0; height: 2em; margin: 0 auto;  }
21
		.scroll-bar-wrap .ui-handle-helper-parent { position: relative; width: 100%; height: 100%; margin: 0 auto; }
22
		.scroll-bar-wrap .ui-slider-handle { top:.2em; height: 1.5em; }
23
		.scroll-bar-wrap .ui-slider-handle .ui-icon { margin: -8px auto 0; position: relative; top: 50%; }
24
	</style>
25
	<script type="text/javascript">
26
	$(function() {
27
		//scrollpane parts
28
		var scrollPane = $('.scroll-pane');
29
		var scrollContent = $('.scroll-content');
30
 
31
		//build slider
32
		var scrollbar = $(".scroll-bar").slider({
33
			slide:function(e, ui){
34
				if( scrollContent.width() > scrollPane.width() ){ scrollContent.css('margin-left', Math.round( ui.value / 100 * ( scrollPane.width() - scrollContent.width() )) + 'px'); }
35
				else { scrollContent.css('margin-left', 0); }
36
			}
37
		});
38
 
39
		//append icon to handle
40
		var handleHelper = scrollbar.find('.ui-slider-handle')
41
		.mousedown(function(){
42
			scrollbar.width( handleHelper.width() );
43
		})
44
		.mouseup(function(){
45
			scrollbar.width( '100%' );
46
		})
47
		.append('<span class="ui-icon ui-icon-grip-dotted-vertical"></span>')
48
		.wrap('<div class="ui-handle-helper-parent"></div>').parent();
49
 
50
		//change overflow to hidden now that slider handles the scrolling
51
		scrollPane.css('overflow','hidden');
52
 
53
		//size scrollbar and handle proportionally to scroll distance
54
		function sizeScrollbar(){
55
			var remainder = scrollContent.width() - scrollPane.width();
56
			var proportion = remainder / scrollContent.width();
57
			var handleSize = scrollPane.width() - (proportion * scrollPane.width());
58
			scrollbar.find('.ui-slider-handle').css({
59
				width: handleSize,
60
				'margin-left': -handleSize/2
61
			});
62
			handleHelper.width('').width( scrollbar.width() - handleSize);
63
		}
64
 
65
		//reset slider value based on scroll content position
66
		function resetValue(){
67
			var remainder = scrollPane.width() - scrollContent.width();
68
			var leftVal = scrollContent.css('margin-left') == 'auto' ? 0 : parseInt(scrollContent.css('margin-left'));
69
			var percentage = Math.round(leftVal / remainder * 100);
70
			scrollbar.slider("value", percentage);
71
		}
72
		//if the slider is 100% and window gets larger, reveal content
73
		function reflowContent(){
74
				var showing = scrollContent.width() + parseInt( scrollContent.css('margin-left') );
75
				var gap = scrollPane.width() - showing;
76
				if(gap > 0){
77
					scrollContent.css('margin-left', parseInt( scrollContent.css('margin-left') ) + gap);
78
				}
79
		}
80
 
81
		//change handle position on window resize
82
		$(window)
83
		.resize(function(){
84
				resetValue();
85
				sizeScrollbar();
86
				reflowContent();
87
		});
88
		//init scrollbar size
89
		setTimeout(sizeScrollbar,10);//safari wants a timeout
90
	});
91
	</script>
92
</head>
93
<body>
94
 
95
<div class="demo">
96
 
97
<div class="scroll-pane ui-widget ui-widget-header ui-corner-all">
98
	<div class="scroll-content">
99
		<div class="scroll-content-item ui-widget-header">1</div>
100
		<div class="scroll-content-item ui-widget-header">2</div>
101
		<div class="scroll-content-item ui-widget-header">3</div>
102
		<div class="scroll-content-item ui-widget-header">4</div>
103
		<div class="scroll-content-item ui-widget-header">5</div>
104
		<div class="scroll-content-item ui-widget-header">6</div>
105
		<div class="scroll-content-item ui-widget-header">7</div>
106
		<div class="scroll-content-item ui-widget-header">8</div>
107
		<div class="scroll-content-item ui-widget-header">9</div>
108
		<div class="scroll-content-item ui-widget-header">10</div>
109
		<div class="scroll-content-item ui-widget-header">11</div>
110
		<div class="scroll-content-item ui-widget-header">12</div>
111
		<div class="scroll-content-item ui-widget-header">13</div>
112
		<div class="scroll-content-item ui-widget-header">14</div>
113
		<div class="scroll-content-item ui-widget-header">15</div>
114
		<div class="scroll-content-item ui-widget-header">16</div>
115
		<div class="scroll-content-item ui-widget-header">17</div>
116
		<div class="scroll-content-item ui-widget-header">18</div>
117
		<div class="scroll-content-item ui-widget-header">19</div>
118
		<div class="scroll-content-item ui-widget-header">20</div>
119
	</div>
120
	<div class="scroll-bar-wrap ui-widget-content ui-corner-bottom">
121
		<div class="scroll-bar"></div>
122
	</div>
123
</div>
124
 
125
 
126
 
127
</div><!-- End demo -->
128
 
129
 
130
 
131
<div class="demo-description">
132
 
133
<p>Use a slider to manipulate the positioning of content on the page. In this case, it acts as a scrollbar with the potential to capture values if needed.</p>
134
 
135
</div><!-- End demo-description -->
136
 
137
</body>
138
</html>