Another Cycle pause/resume not working issue (detailed homework done)
I've successfully implemented Cycle along with some additional code which uses the youtube JS API to communicate video pause and play events.
I have disabled pause on hover and created my own mouse events for pausing and starting the slideshow.
I have gone as far as to add a console log line to the pause event in jquery.all.js to trace the pause event as I felt passing the command to Cycle wasn't making it to the slider.
- case 'pause':
- cont.cyclePause = 1;
- triggerPause(cont);
- console.log("$$$ cycle is paused $$$"); //added this to trace
- return false;
My mouse events look like this...
- jQuery('#slider').mouseenter(function(){
- jQuery('#slider').cycle("pause");
- sliderstate = "paused";
- console.log("MOUSE ENTER EVENT TRIGGERED SLIDER STATE : " + sliderstate);
- });
- jQuery('#slider').mouseleave(function(){
- // **IF SLIDER IS PAUSED AND(BECAUSE) VIDEO IS PLAYING DON'T RESUME SLIDER
- if (sliderstate == "paused" && playerstate != 1){
- console.log("DO NOTHING!");
- }else{
- // **RESUME SLIDER
- jQuery('#slider').cycle("resume");
- sliderstate = "playing";
- };
- console.log("MOUSE LEAVE EVENT TRIGGERED SLIDER STATE : " + sliderstate);
- });
Ignoring the playerstate contitional for a moment.. the trace in my jquery.cycle.all.js returns
$$$ cycle is paused $$$
to the console window which to me, means the command jQuery('#slider').cycle("resume"); is being triggered in the base code... unfortunately, the slider continues to play once the timeout (time before next slide appears) is reached even if keep my mouse over the slider.
I've also tried sending other control commands with no effect (toggle, stop, prev, next)
Once I get this issue figured out it's only a short step to get my video buffering/playing/paused conditionals working to control cycle's pause/resume.
here is my slider init code...
- $slider = {
- context: false,
- tabs: false,
- timeout: 6000,
- slideSpeed: 1000,
- fx: 'scrollDown',
-
-
- init: function() {
- // set the context to help speed up selectors/improve performance
- this.context = jQuery('#slider');
-
- // set tabs to current hard coded navigation items
- this.tabs = jQuery('ul.slides-nav li', this.context);
- this.headers = jQuery('ul.slider-headers li', this.context);
-
- // remove hard coded navigation items from DOM
- // because they aren't hooked up to jQuery cycle
- this.tabs.remove();
-
- // prepare slider and jQuery cycle tabs
- this.prepareSlideshow();
- },
-
- prepareSlideshow: function() {
- // initialise the jquery cycle plugin -
- // for information on the options set below go to:
- // http://malsup.com/jquery/cycle/options.html
- jQuery('div.slides > ul', $slider.context).cycle({
- fx: $slider.fx,
- timeout: $slider.timeout,
- speed: $slider.slideSpeed,
- fastOnEvent: $slider.tabSpeed,
- pager: jQuery('ul.slides-nav', $slider.context),
- pagerAnchorBuilder: $slider.prepareTabs,
- before: $slider.activateTab,
- //pauseOnPagerHover: true,
- //pause: true
- });
- },
- prepareTabs: function(i, slide) {
- // return markup from hardcoded tabs for use as jQuery cycle tabs
- // (attaches necessary jQuery cycle events to tabs)
- return $slider.tabs.eq(i);
- },
- activateTab: function(currentSlide, nextSlide) {
- // get the active tab
- var activeTab = jQuery('a[href="#' + nextSlide.id + '"]', $slider.context);
-
- // if there is an active tab
- if(activeTab.length) {
- // remove active styling from all other tabs
- $slider.tabs.removeClass('on');
- // add active styling to active button
- activeTab.parent().addClass('on');
- }
- }
- };
- jQuery(function() {
- // add a 'js' class to the body
- jQuery('body').addClass('js');
- // initialise the slider when the DOM is ready
- $slider.init();
- });
Thanks!