0

こんにちは、私はパフォーマンスを改善したいアプリケーションに取り組んでいます.(私は質問がちょっと長いものであることを知っています.

qtscript/qscript(一種のjavascript)のみを使用し、htmlを使用しない入札アプリケーションについて詳しく説明します。

ユーザーがボタンをクリックすると、テキストフィールドをポイントしたいと思います(通常のユーザーの場合、1秒あたり-1または2クリックで十分です)。しかし、ユーザーは狂ったようにボタンをクリックします (1 秒あたり 5 ~ 10 回のクリック - ええ、そのようにクリックする人もいます)。

ユーザーが 1 秒間に 3 回以上クリックした場合に、最後のクリックの後にのみフォーカス関数を呼び出すような回避策を考えています。もう 1 つの問題は、setInterval() と clearInterval() を使用できないことです。

どんな助けでも大歓迎です。

4

3 に答える 3

1

まず、ユーザーが特定のボタンをクリックした後に選択するテキスト編集に既にフォーカスがあることを確認する必要があります。これにより、イベント キューの負荷が大幅に軽減されます。

次に、(サブクラス化によって) 独自のボタンを実装し、オプションをいじることができます。たとえば、特定の (短い) 間隔内のクリックを無視するなどです。ユーザーがクリックを非常に速く生成し始めた場合、特定の方法でボタン上でそれを「視覚化」して、アプリケーションがユーザー入力に対する反応を制限していることをユーザーに示し、指定されたタイムアウト後にオフにすることもできます。

于 2013-08-09T22:02:23.783 に答える
1

example.xhtml - フレームワークなし、本文にスクリプト要素なし、左クリックと右クリックの両方をカウントします。

e.preventDefault();さらに、匿名onclickイベント関数の最後に追加できます。コンテンツを保護しようとしている場合、コンテンツが既に自分のコンピューター (メモリ、キャッシュなど) にある場合、それが既に所有されていることに気付くほど賢い人に対しては、最終的には失敗することに注意してください。画像を保護しようとしている場合は、透かしを使用する必要があります。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Click Counter</title>

<script type="application/javascript">
//<![CDATA[
var click_left = 0;
var click_right = 0;

window.onclick = function(e)
{
 if (e.which==1) {click_left++;}
 else if (e.which==3) {click_right++;}

 alert('Left clicks: '+click_left+'\n\nRight Clicks: '+click_right);
}
//]]>
</script>
</head>

<body>

<div><p>Left or right click</p></div>

</body>
</html>
于 2013-08-09T17:44:16.883 に答える
1

Underscore.js_.throttle関数を見てみましょう。

_.throttle = function(func, wait, options) {
  var context, args, result;
  var timeout = null;
  var previous = 0;
  options || (options = {});
  var later = function() {
    previous = options.leading === false ? 0 : new Date;
    timeout = null;
    result = func.apply(context, args);
  };
  return function() {
    var now = new Date;
    if (!previous && options.leading === false) previous = now;
    var remaining = wait - (now - previous);
    context = this;
    args = arguments;
    if (remaining <= 0) {
      clearTimeout(timeout);
      timeout = null;
      previous = now;
      result = func.apply(context, args);
    } else if (!timeout && options.trailing !== false) {
      timeout = setTimeout(later, remaining);
    }
    return result;
  };
};

非常に複雑に見えますが、基本的な例は次のとおりです。

var func = function(){alert("Only do this once every second");},
    throttled = _.throttle(func, 1000);

// Call func() three times in under a second, and
// you get 3 message boxes
func(); // alerts
func(); // alerts
func(); // alerts

// Call throttled() three times in under a second, and
// you only get a message box the first time
func(); // alerts
throttled(); // does nothing
throttled(); // does nothing

// ... wait >1 second ...
func(); // alerts
throttled(); // does nothing
throttled(); // does nothing
于 2013-08-09T17:44:41.840 に答える