神刀安全网

Spatial Navigation

Spatial navigation is the ability to navigate to focusable elements based on their position in a given space.  Spatial navigation is a must when your site or app must respond to arrow keys, a perfect example being a television with directional pad remote.  Firefox OS TV apps are simply HTML5 wrapped in a chromeless browser shell (Gecko) so most apps require spacial navigation to ensure the physical television remote is useful.  Mozilla’s Luke Chang has created SpatialNavigation to make implementing JavaScript navigation easy and flexible!

View Demo

SpatialNavigation boasts features like:

  • Completely stylable focus elements
  • Definable regions
  • Integration with jQuery
  • Awesome performance

A simple example usage of SpatialNavigation:

// Initialize SpatialNavigation.init();  // Define navigable elements (anchors and elements with "focusable" class). SpatialNavigation.add({   selector: 'a, .focusable' });  // Make the *currently existing* navigable elements focusable. SpatialNavigation.makeFocusable();  // Focus the first navigable element. SpatialNavigation.focus();
<body>   <a href="#">Link 1</a>   <a href="#">Link 2</a>   <div class="focusable">Div 1</div>   <div class="focusable">Div 2</div> </body>
/* Add style to the focused elements */ a:focus, .focusable {   outline: 2px solid red; }

While the demo above is fairly simple, we know that dynamic apps are not simple.  The SpatialNavigation repository features more than a dozen unique example usages of the utility, from the most basic to very complex.  I encourage you to explore these demos to see all that SpatialNavigation has to offer.

View Demo

Spatial navigation can also play a role on desktop websites; many sites these days use a flexbox grid layout which could make great use directional arrows.  You’d need to be careful about CMD+up and CMD+down for full page scrolling, of course, but spatial navigation in that space would be useful.

Spatial Navigation Spatial Navigation Spatial Navigation Spatial Navigation Spatial Navigation

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Spatial Navigation

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮