在我的控制台中,我的以下脚本不仅在单击鼠标滚轮时开始记录,而且在您停止按住鼠标滚轮按钮后继续记录。
var mPosX,
mPosY;
$(document).on('mousedown', function (e) {
"use strict";
if( e.which === 2 ) {
e.preventDefault();
mPosX = event.pageX;
mPosY = event.pageX;
$(document).mousemove(function(event){
var CmPosX = event.pageX,
CmPosY = event.pageX;
console.log('Original X: ' + mPosX + ', New X: ' + CmPosX + ' | Original Y: ' + mPosY + ', New Y: ' + CmPosY);
});
}
});
如何让我的脚本仅在鼠标滚轮被按下时记录并在释放时停止?
答案 0 :(得分:2)
您可以在public function getPhotos($nav, $page=false)
{
if($page==false){
$dir = 'img/'.$nav;
}
else{
$dir = 'img/'.$nav.'/'.$page;
}
$files = FILE::allFiles($dir);
foreach($files as $file){
if(pathinfo($file, PATHINFO_EXTENSION)=='png' or pathinfo($file, PATHINFO_EXTENSION)=='gif' or pathinfo($file, PATHINFO_EXTENSION)=='jpg'){
$result[] = (string)explode("$page\\",$file)[1];
}
}
echo $json_response = json_encode($result);
}
和mousedown
中存储可以在mouseup
mousemove

$(document).on({
mousedown: function(e) {
e.preventDefault();
if (e.which === 2)
$(window).data('isDown', true).data('mPosX', e.pageX).data('mPosY', e.pageY);
},
mouseup: function(e) {
e.preventDefault();
if (e.which === 2)
$(window).data('isDown', false);
},
mousemove: function(e) {
if ($(window).data('isDown')) {
var CmPosX = e.pageX,
CmPosY = e.pageY,
mPosX = $(window).data('mPosX'),
mPosY = $(window).data('mPosY');
console.log('Original X: ' + mPosX +
', New X: ' + CmPosX +
' | Original Y: ' + mPosY +
', New Y: ' + CmPosY);
}
}
});