【问题标题】:fullpagejs pause on hover整页js在悬停时暂停
【发布时间】:2017-01-27 10:32:00
【问题描述】:

js,我想在鼠标悬停在 h1 标签时暂停滑块,但它没有,我知道这是 javascript 的问题,但我无法让它工作

http://jsfiddle.net/2dhkR/405/

$(document).ready(function() {
    $('#fullpage').fullpage({
        sectionsColor: ['#1bbc9b', '#4BBFC3'],
        loopBottom: true,
        afterRender: function() {
            setInterval(function() {
                $.fn.fullpage.moveSlideRight();
            }, 3000);
        }
    });


    // the function - set var up just in case
    // the timer isn't running yet
    var timer = null;

    function startSetInterval() {
        timer = setInterval(showDiv, 5000);
    }
    // start function on page load
    startSetInterval();

    // hover behaviour
    function showDiv() {
        $('#fullpage h1').hover(function() {
            clearInterval(timer);
        }, function() {
            startSetInterval();
        });
    }

}); 

任何帮助将不胜感激,谢谢

【问题讨论】:

    标签: javascript setinterval fullpage.js


    【解决方案1】:

    http://jsfiddle.net/2dhkR/407/

    var interval = undefined;
    $(document).ready(function() {
    
        $('#fullpage').fullpage({
            sectionsColor: ['#1bbc9b', '#4BBFC3'],
            loopBottom: true,
            afterRender: function() {
               interval = setInterval(function() {
                    $.fn.fullpage.moveSlideRight();
                }, 100);
            }
        });
      $('#fullpage h1').mouseover(function() {
        clearInterval(interval);
        interval = null;
      })
       $('#fullpage h1').mouseout(function() {
                 interval = setInterval(function() {
                    $.fn.fullpage.moveSlideRight();
                }, 100);
      });
    
    
    }); // end document ready
    

    【讨论】:

      【解决方案2】:

      很简单的方法(也许不是最清楚的)用一个布尔:

      var go = true;
      
      if (go)$.fn.fullpage.moveSlideRight();
      
      $('#fullpage h1').hover(function() {
              go = false;
              clearInterval(timer);
          }, function() {
              go = true;
              startSetInterval();
          });
      

      【讨论】:

      • 我收到以下错误:- ReferenceError: timer is not defined - ReferenceError: startSetInterval is not defined.. 你能用工作版本更新小提琴吗? jsfiddle.net/2dhkR/405
      • 对不起,我没有解释你必须在哪里添加:) 这是小提琴jsfiddle.net/2dhkR/410
      【解决方案3】:

      尝试在 mouseenter 上使用 jQuery 的 hover(),然后在 mouseleave 上再次启动滑块。

      $(function() {
      var interval = setInterval( slideSwitch, 10000 );
      
      $('#slideshow').hover(function() {
          clearInterval(interval);
      }, function() {
          interval = setInterval( slideSwitch, 10000 );
      });
      

      });

      【讨论】:

      • 谢谢,但我收到以下错误 ReferenceError: slideSwitch is not defined
      • 你能用相同的ocde提到你的html
      猜你喜欢
      • 2014-06-19
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-09
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      相关资源
      最近更新 更多