我正在使用Ariel Flesler的ScrollTo jQuery插件。一切都很棒,除非滚动时,动画将光标拖动到一些链接上,这些链接具有:悬停触发器,导致动画中的瞬间挂起。任何人都知道如何禁用元素:动画发生时悬停功能?

有帮助吗?

解决方案

当你说链接有“:hover triggers”时,你的意思是你已经定义了CSS:悬停规则或者你已经将JavaScript函数绑定到悬停事件了吗?

如果是CSS,你设置了什么属性导致挂起(我不能通过简单的字体大小更改复制挂在我的机器上)。据我所知,你无法阻止CSS:悬停。

如果是JavaScript,你不能在调用scrollTo之前取消绑定事件吗?

稍微详细一点或一个例子会很有用。

修改

好的,在回复你的评论时,基本上你必须 unbind mouseenter mouseleave 事件才能使用 scrollTo

$(...).unbind('mouseenter mouseleave');

演示

访问 http://demos.flesler.com/jquery/scrollTo/#目标示例并在Firebug中运行以下代码。

然后,您可以点击“测试滚动”按钮。链接来测试代码。当鼠标悬停在其余链接上时,您应该看到浏览器没有挂起。

当滚动停止时,您可以点击任何“返回”按钮。链接,它会向后滚动,除非这次它不会解除悬停事件的绑定,所以浏览器应该挂起。

注意:我根本没有遇到任何悬挂。您是使用慢速计算机还是旧版本的jquery?如果演示按预期工作,请告诉我。

/*
  Inject some CSS to add a background to the elements we
  are going to hover over and increase the font-size to 
  make the hover area bigger.
*/
$('head').append('<style type="text/css"> .back { font-size:3em!important; background-image:url(http://imgs.xkcd.com/comics/useless.jpg); background-repeat:no-repeat; } </style>');

/*
  Setup the hover events -- change the backgroundPosition
  and fade the elements in and out.
*/
function hoverOn() {    
  $(this)
    .css('backgroundPosition','-95px -210px')
    .fadeTo('normal', 1);
}

function hoverOff(){
  $(this)
    .css('backgroundPosition','-260px -110px')
    .fadeTo('normal', 0.5);
}

// Set the default opacity and bind the hover events
$('.back').not('#pane-target a:first')
  .css('opacity', 0.5)
  .hover(hoverOn, hoverOff);

// Modify the first link so that we can use it to trigger the scroll.
$('#pane-target a').eq(0)
  .css('backgroundImage', 'none') // Remove the backgroundImage for clarity
  .unbind('click') // unbind the old "go back" behaviour
  .text('test scroll')
  .click(function(){ 

    // unbind the hover events so that they don't hang the browser
    $('.back').not('#pane-target a:first')
      .unbind('mouseenter mouseleave');

    $('#pane-target').scrollTo(
      'li:eq(5)',
      800,
      {onAfter:function(){
        // re-bind the hover events
        $('.back').not('#pane-target a:first').hover(hoverOn, hoverOff);
      }}
    );

    return false;
  });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top