| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="iso-8859-1"> |
| 5 |
<title>Testing mousewheel plugin</title> |
| 6 |
|
| 7 |
<style> |
| 8 |
html { |
| 9 |
font: 13px Arial, sans-serif; |
| 10 |
} |
| 11 |
|
| 12 |
#stage { |
| 13 |
color: #fff; |
| 14 |
position: relative; |
| 15 |
zoom: 1; |
| 16 |
} |
| 17 |
|
| 18 |
#test1, #test2, #test3, #test4, #test5, #test6, #test7 { |
| 19 |
float: left; |
| 20 |
} |
| 21 |
|
| 22 |
#test1 { |
| 23 |
background-color: #000; |
| 24 |
width: 120px; |
| 25 |
height: 100px; |
| 26 |
} |
| 27 |
|
| 28 |
#test2 { |
| 29 |
background-color: #333; |
| 30 |
width: 120px; |
| 31 |
height: 100px; |
| 32 |
} |
| 33 |
|
| 34 |
#test3 { |
| 35 |
background-color: #666; |
| 36 |
width: 120px; |
| 37 |
height: 100px; |
| 38 |
} |
| 39 |
|
| 40 |
#test4 { |
| 41 |
background-color: #000; |
| 42 |
width: 120px; |
| 43 |
height: 100px; |
| 44 |
} |
| 45 |
|
| 46 |
#test5 { |
| 47 |
background-color: #333; |
| 48 |
padding: 5px; |
| 49 |
width: 400px; |
| 50 |
height: 400px; |
| 51 |
} |
| 52 |
|
| 53 |
#test6 { |
| 54 |
background-color: #666; |
| 55 |
padding: 5px; |
| 56 |
width: 250px; |
| 57 |
height: 250px; |
| 58 |
} |
| 59 |
|
| 60 |
#test7 { |
| 61 |
background-color: #000; |
| 62 |
padding: 5px; |
| 63 |
width: 100px; |
| 64 |
height: 100px; |
| 65 |
} |
| 66 |
|
| 67 |
#forceScroll { |
| 68 |
clear: both; |
| 69 |
height: 1000px; |
| 70 |
} |
| 71 |
|
| 72 |
#logger { |
| 73 |
position: absolute; |
| 74 |
top: 100px; |
| 75 |
left: 0; |
| 76 |
width: 480px; |
| 77 |
height: 310px; |
| 78 |
overflow: auto; |
| 79 |
z-index: 100; |
| 80 |
} |
| 81 |
|
| 82 |
#logger p { |
| 83 |
color: #000; |
| 84 |
padding: 2px; |
| 85 |
border-bottom: 1px solid #ccc; |
| 86 |
margin: 0; |
| 87 |
} |
| 88 |
|
| 89 |
#logger p:nth-child(even) { |
| 90 |
background-color: #ffffe8; |
| 91 |
} |
| 92 |
|
| 93 |
#logger p:nth-child(10n) { |
| 94 |
border-bottom-color: #000; |
| 95 |
} |
| 96 |
</style> |
| 97 |
|
| 98 |
<script> |
| 99 |
( function() { |
| 100 |
var src, |
| 101 |
verMatch = /\bjquery=(\d\.\d\.\d(?:\.slim)?(?:\.min)?)/, |
| 102 |
version = ( window.location.search.match( verMatch ) || [ "", "git" ] )[ 1 ]; |
| 103 |
if ( !version || version === "git" || version === "3.x-git" ) { |
| 104 |
src = "https://releases.jquery.com/git/jquery-" + version + ".js" |
| 105 |
} else { |
| 106 |
src = "https://code.jquery.com/jquery-" + version + ".js"; |
| 107 |
} |
| 108 |
document.write( "<script src=\"http://" + src + ".js\"><\/script>" ); |
| 109 |
} )(); |
| 110 |
</script> |
| 111 |
<script> |
| 112 |
$( function() { |
| 113 |
$( "#userAgent" ).html( navigator.userAgent ); |
| 114 |
$( "#jqueryVersion" ).html( $.fn.jquery ); |
| 115 |
|
| 116 |
var loghandle = function( event, delta ) { |
| 117 |
var o = "", id = event.currentTarget.id || event.currentTarget.nodeName; |
| 118 |
|
| 119 |
o = "#" + id + ":"; |
| 120 |
|
| 121 |
if ( delta > 0 ) { |
| 122 |
o += " up (" + delta + ")"; |
| 123 |
} else if ( delta < 0 ) { |
| 124 |
o += " down (" + delta + ")"; |
| 125 |
} |
| 126 |
|
| 127 |
if ( event.deltaY > 0 ) { |
| 128 |
o += " north (" + event.deltaY + ")"; |
| 129 |
} else if ( event.deltaY < 0 ) { |
| 130 |
o += " south (" + event.deltaY + ")"; |
| 131 |
} |
| 132 |
|
| 133 |
if ( event.deltaX > 0 ) { |
| 134 |
o += " east (" + event.deltaX + ")"; |
| 135 |
} else if ( event.deltaX < 0 ) { |
| 136 |
o += " west (" + event.deltaX + ")"; |
| 137 |
} |
| 138 |
|
| 139 |
o += " deltaFactor (" + event.deltaFactor + ")"; |
| 140 |
|
| 141 |
log( o ); |
| 142 |
}; |
| 143 |
|
| 144 |
$( document ) |
| 145 |
.mousewheel( function( event, delta ) { |
| 146 |
loghandle( event, delta ); |
| 147 |
} ); |
| 148 |
|
| 149 |
$( "#test1" ) |
| 150 |
.mousewheel( function( event, delta ) { |
| 151 |
loghandle( event, delta ); |
| 152 |
log( "pageX: " + event.pageX + " pageY: " + event.pageY ); |
| 153 |
} ); |
| 154 |
|
| 155 |
$( "#test2" ) |
| 156 |
.mousewheel( function( event, delta ) { |
| 157 |
loghandle( event, delta ); |
| 158 |
return false; // prevent default |
| 159 |
} ); |
| 160 |
|
| 161 |
$( "#test3" ) |
| 162 |
.hover( |
| 163 |
function() { |
| 164 |
log( "#test3: mouseover" ); |
| 165 |
}, |
| 166 |
function() { |
| 167 |
log( "#test3: mouseout" ); |
| 168 |
} |
| 169 |
) |
| 170 |
.mousewheel( function() { |
| 171 |
log( "#test3: I should not have been logged" ); |
| 172 |
} ) |
| 173 |
.unmousewheel(); |
| 174 |
|
| 175 |
var testRemoval = function() { |
| 176 |
log( "#test4: I should not have been logged" ); |
| 177 |
}; |
| 178 |
|
| 179 |
$( "#test4" ) |
| 180 |
.mousewheel( function( event, delta ) { |
| 181 |
loghandle( event, delta ); |
| 182 |
return false; |
| 183 |
} ) |
| 184 |
.mousewheel( testRemoval ) |
| 185 |
.mousewheel( function( event, delta ) { |
| 186 |
loghandle( event, delta ); |
| 187 |
return false; |
| 188 |
} ) |
| 189 |
.unmousewheel( testRemoval ); |
| 190 |
|
| 191 |
$( "#test5" ) |
| 192 |
.mousewheel( function( event, delta ) { |
| 193 |
loghandle( event, delta ); |
| 194 |
event.stopPropagation(); |
| 195 |
event.preventDefault(); |
| 196 |
} ); |
| 197 |
|
| 198 |
$( "#test6" ) |
| 199 |
.mousewheel( function( event, delta ) { |
| 200 |
loghandle( event, delta ); |
| 201 |
event.stopPropagation(); |
| 202 |
event.preventDefault(); |
| 203 |
} ); |
| 204 |
|
| 205 |
$( "#test7" ) |
| 206 |
.mousewheel( function( event, delta ) { |
| 207 |
loghandle( event, delta ); |
| 208 |
event.preventDefault(); |
| 209 |
} ); |
| 210 |
|
| 211 |
function log( msg ) { |
| 212 |
$( "#logger" ).append( "<p>" + msg + "<\/p>" )[ 0 ].scrollTop = 999999; |
| 213 |
} |
| 214 |
} ); |
| 215 |
</script> |
| 216 |
<script src="../jquery.mousewheel.js"></script> |
| 217 |
</head> |
| 218 |
<body> |
| 219 |
<h1 id="banner">jQuery mousewheel.js Test with jQuery <span id="jqueryVersion"></span></h1> |
| 220 |
<h2 id="userAgent"></h2> |
| 221 |
|
| 222 |
<ul> |
| 223 |
<li><strong>Test1</strong> is just using the plain on <code>mousewheel()</code> with a function passed in and does not prevent default. (Also logs the value of <code>pageX</code> and <code>pageY</code> event properties.)</li> |
| 224 |
<li><strong>Test2</strong> should prevent the default action.</li> |
| 225 |
<li><strong>Test3</strong> should only log a <code>mouseover</code> and <code>mouseout</code> event. Testing <code>unmousewheel()</code>.</li> |
| 226 |
<li><strong>Test4</strong> has two handlers.</li> |
| 227 |
<li><strong>Test5</strong> is like Test2 but has children. The children should not scroll until mousing over them.</li> |
| 228 |
<li><strong>Test6</strong> is like Test5 but should not scroll children or parents.</li> |
| 229 |
<li><strong>Test7</strong> is like Test6 but has no children. It will propagate the event and scroll test 6 as well.</li> |
| 230 |
</ul> |
| 231 |
|
| 232 |
|
| 233 |
<div id="stage"> |
| 234 |
<div id="test1"><p>Test1</p></div> |
| 235 |
<div id="test2"><p>Test2</p></div> |
| 236 |
<div id="test3"><p>Test3</p></div> |
| 237 |
<div id="test4"><p>Test4</p></div> |
| 238 |
<div id="test5"> |
| 239 |
<p>Test5</p> |
| 240 |
<div id="test6"> |
| 241 |
<p>Test6</p> |
| 242 |
<div id="test7"><p>Test7</p></div> |
| 243 |
</div> |
| 244 |
</div> |
| 245 |
<div id="logger"></div> |
| 246 |
</div> |
| 247 |
|
| 248 |
<div id="forceScroll"></div> |
| 249 |
</body> |
| 250 |
</html> |