iframe - Keep listening for jquery keydown events regardless of focus -


the situation

i building basic slide deck in html, css & javascript. based on jquery cycle plugin. slides simple li items contain either images, text or iframes (e.g. youtube, or webpage i.e not pages live on domain/have control over). have next , previous buttons working jquery keydown working well, user not have use mouse move through slides

the problem

when have keyed through li contains iframe, if user clicks iframe focus shifted iframe (as you'd expect) , in order move next slide have refocus onto next or previous buttons mouse click. there anyway keep page listening keydown events in parent regardless of focus within page is?

also if possible

it great if there solution involved automatically bringing iframe focus (as maintaining next/prev mentioned) when slide active example use space bar play/pause youtube video , click left move next slide. want not have use mouse if not necessary.

key press code below (you'd need cycle plugin & of code deck working - can provide if necessary feel there generic solution here consistently listening keydown events used in other contexts)

jquery keypress

    $(document).ready(function () {          $("body").keydown(function(e) {             if(e.keycode == 37) { // left                 $("#prev").click();                 return false;                 }             else if(e.keycode == 39) { // right                 $("#next").click();                 }          });     }); 

html

<body>   <ul class="images">      <!-- basic slide example -->      <li class="wrapper" title="test slide 01"></li>       <!-- example iframe -->      <li class="wrapper" title="test slide 02" >     <iframe width="100%" height="100%" id="iframe"      src="http://www.youtube.com/embed/blpwhbn6ikg?wmode=transparent" frameborder="0" allowfullscreen>        </iframe>     </li>    </ul>      <div id="prev">     </div>     <div id="next">     </div> 

cycle plugin i'm using

http://malsup.github.io/jquery.cycle.all.js

my options

$(function() {var index=0,hash=window.location.hash;if(hash){index=/\d+/.exec(hash)[0];index=(parseint(index)||1)-1;}       $('.images')     .before('<div id="nav">')      .cycle({         prev:   '#prev',         next:   '#next',         timeout: 0,         slideresize: 0,         containerresize: 0,         startingslide:index,         pager:  '#nav',         before: onbefore,         pageranchorbuilder: function(i, slide) {         return '<a href="#"><p>' + $(slide).attr('title') + ' </p></a>';},         after:function(curr,next,opts){window.location.hash=opts.currslide+1;}         });          function onbefore() {              $('#caption')              .html(this.h1);          };  });   function setslide(index) {             $('.images').cycle(index);         } 

css prev & next

#prev, #next{ width: 40px; height: 100%; position: absolute; bottom: 90px; cursor: pointer; z-index: 1100; 

i hope that's clear, appreciated. solution not have supported in every browser, minimum requirement works in chrome.

thank you!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -