Javascript iPhoneのスクロールの効果にiFrame/Javascriptマウスの加速
-
22-08-2019 - |
質問
私を再現しようと、iPhoneフリック/クロールイベントウィンドウにJavaScriptを使用しております。
はじめJQueryっ測定し、マウスの加速度とオフセットの中をクリック-ドラッグ-リリース記念イベントータ:
var MouseY = {
init: function(context) {
var self = this;
self._context = context || window
self._down = false;
self._now = 0;
self._last = 0;
self._offset = 0;
self._timer = 0;
self._acceleration = 0;
$(self._context).mousedown(function() {self._down = true;});
$(self._context).mouseup(function() {self._down = false;});
$(self._context).mousemove(function(e) {self.move(e);});
},
move: function(e) {
var self = this;
self._timer++;
self._last = self._now;
self._now = e.clientY + window.document.body.scrollTop;
self._offset = self._now - self._last;
self._acceleration = self._offset / self._timer;
},
reset: function() {
this._offset = 0;
this._acceleration = 0;
this._timer = 0;
}
};
$(function() {
MouseY.init();
setInterval(function() {
$('#info').html(
'_acceleration:' + MouseY._acceleration + '<br />' +
'_now:' + MouseY._now + '<br />' +
'_offset:' + MouseY._offset + '<br />' +
'_timer:' + MouseY._timer + '<br />'
);
MouseY.reset();
}, 10);
});
現在の問題は、翻訳に加速度を画面に移動があるアルゴリズム(緩和?) アニメーション図書館が教えてくれるので助かります。(私見JQueryます。アニメーション(がんの美しく雄大なぢ大自然に包どのように適用するとともに、継続的な中にドラッグイベントが盛りだくさん!
更新-最終解決。
解決
ヒットはこのリンクの説明の一つのアプローチのようだ。
http://www.faqts.com/knowledge_base/view.phtml/aid/14742/fid/53
こちらの抜粋:
このハンドラをセットアップイベント キャプチャーにマウスの移動および店舗 マウスカーソルの位置変数 mouseXとmouseY.その タイマー monitorMouse()に対 マウスカーソルスピードによるサンプリングの 値がこれらの変数を定期的 間隔とします。変数をmouseLeft とmouseTop催の各サンプリングマウス 位置およびサンプリング率 セットには100ミリ秒の 変数モニタです。timerDelay.
一部のコード:
nn4 = (document.layers)? true:false;
mouseLeft = mouseTop = mouseX = mouseY = 0;
monitor = {
timerDelay:100,
moveLimit:2,
sampleLimit:10
};
function startMonitor(thisText) {
if (!tip) return;
toolTipText = thisText;
writeTooltip(toolTipText);
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = function (evt) {
mouseX = evt.pageX;
mouseY = evt.pageY;
return true;
}
monitorMouse();
}
function stopMonitor() {
if (!tip) return;
hideTooltip();
if (monitor.timer) {
clearTimeout(monitor.timer);
monitor.timer = null;
}
document.releaseEvents(Event.MOUSEMOVE);
document.onmousemove = null;
monitor.slowSamples = 0;
}
function monitorMouse() {
if (Math.abs(mouseX - mouseLeft) > monitor.moveLimit
|| Math.abs(mouseY - mouseTop) > monitor.moveLimit)
{
monitor.slowSamples = 0;
}
else if (++monitor.slowSamples > monitor.sampleLimit) {
showTooltip();
return;
}
mouseLeft = mouseX;
mouseTop = mouseY;
monitor.timer = setTimeout("monitorMouse()",monitor.timerDelay);
}
他のヒント
ここで私が見つかりが運動-運動量スクロール図書館:
おに興味を持っているかもしれのjQueryプラグイン名overscroll:http://www.azoffdesign.com/overscroll (GitHubのページ)
所属していません StackOverflow