Script.aculo.us 快速连续事件导致显示错误...?

发布于 2024-08-06 14:17:02 字数 591 浏览 7 评论 0原文

在 onMouseOver 事件上使用 script.aculo.us Effect.Highlight 效果非常好 - 如果用户仅将鼠标悬停在 DIV 上一次。如果在执行效果期间将鼠标移回 DIV 上,则会安排另一个效果(或并行运行,具体取决于是否

{队列:'结束'}

已启用)。

script.aculo.us 是否有内置方法来防止这种情况发生,以便只有当用户鼠标悬停在静止状态的 DIV 上时,DIV 才会突出显示自身?否则我想我可以保留一个恢复到“休息”状态的变量:

afterFinish: function(obj) { 休息 = true; }

以前注意到过类似的情况:例如,Effect.Shake,如果多次调用,会导致 DIV 在更宽的框架中抖动。

此外,如果您快速连续多次单击演示,则可以在演示网站上看到此问题: 点击查看演示

Using the script.aculo.us Effect.Highlight on an onMouseOver event works perfectly - if the user only mouses over the DIV once. If they mouse back over the DIV during the execution of the effect, another Effect gets scheduled (or runs in parallel, depending on whether or not

{queue: 'end'}

is enabled).

Does script.aculo.us have a built-in way of preventing this from happening, so that the DIV will only highlight itself if the user mouse's over the DIV at a resting state? Otherwise I guess I could keep a state variable that gets restored to 'resting':

afterFinish: function(obj) { resting = true; }

I've noticed similar situations before: for example, Effect.Shake, if called multiple times, causes the DIV to shake in a wider frame.

Also, this problem can be seen on the demo site if you click the demo multiple times in rapid succession: click to see demo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凑诗 2024-08-13 14:17:02

提出了类似于我在问题中提出的解决方案,似乎有效:

$('id').writeAttribute('resting');
//
// other code here
//
if($('id').readAttribute('resting') == 'resting') {
    $('id').writeAttribute('resting',false); 
    new Effect.Highlight('id', {queue: 'end', startcolor:'#b3ff8d', endcolor:'#ffffff',afterFinish:function(obj) {obj.element.writeAttribute('resting')}});
}

Came up with a solution similar to what I proposed in the question, appears to work:

$('id').writeAttribute('resting');
//
// other code here
//
if($('id').readAttribute('resting') == 'resting') {
    $('id').writeAttribute('resting',false); 
    new Effect.Highlight('id', {queue: 'end', startcolor:'#b3ff8d', endcolor:'#ffffff',afterFinish:function(obj) {obj.element.writeAttribute('resting')}});
}
陌伤浅笑 2024-08-13 14:17:02

每次将鼠标悬停在元素上时都会触发 onMouseOver 事件。 Script.aculo.us 没有内置方法来检查您所要求的内容。

但是,您可以做的是在 onMouseOver 上向名为“fired”的元素添加一个类,如果您看到该类未触发,则触发鼠标悬停。

您还可以向 onMouseOut 添加一个计时器,这样,如果他们尝试在计时器耗尽之前将鼠标悬停在该元素上,该元素将不会突出显示。我承认,这可能会变得很棘手。

The onMouseOver event will fire every time you mouse over the element. Script.aculo.us does not have a way built in to check what you're asking for.

However, what you could do is onMouseOver add a class to the element called "fired" and if you see that class don't fire trigger the mouseover.

You could also add a timer to onMouseOut, so if they try to mouse over the element before the timer runs out it won't highlight. I admit, this could get hairy though.

洛阳烟雨空心柳 2024-08-13 14:17:02

由于他们的亮点演示也有同样的问题,我想它就是这样构建的。

我不熟悉 Scriptaculous 库或它所基于的原型。然而,浏览一下 Effect.Highlight 的源代码(当前的第 474 行代码),我们可以看看如何解决您的问题。

我实际上没有尝试过这个,但我想尝试的是这样的:

function MySiteSetup(){
 var highlight = new Effect.Highlight('id_of_element', [options]);

 var firing = false;
 var oldSetup = highlight.setup;
 highlight.setup = function(){
  if(firing) return; // Short circuit the effect if it's already firing

  firing = true;
  oldSetup();
  firing = false;
 }
}

Since their demo of the highlight has the same problem, I imagine its just built that way.

I'm not familiar with the Scriptaculous library, or Prototype upon which it was built. However, glancing at their source code for Effect.Highlight (currently line 474 of the code), we can see what we might do to fix your problem.

I haven't actually tried this, but what I would be tempted to try is something like this:

function MySiteSetup(){
 var highlight = new Effect.Highlight('id_of_element', [options]);

 var firing = false;
 var oldSetup = highlight.setup;
 highlight.setup = function(){
  if(firing) return; // Short circuit the effect if it's already firing

  firing = true;
  oldSetup();
  firing = false;
 }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文