var leftBound = Math.min(point1.x, point2.x);
var rightBound = Math.max(point1.x, point2.x);
var topBound = Math.min(point1.y, point2.y);
var bottomBound = Math.max(point1.y, point2.y);
$(".").filter(function(x) {
var offset = $(this).offset();
var top=offset.top, bottom=top+$(this).height;
var left=offset.left, right=left+$(this).width;
var corners = [[left,top], [left,bottom], [right,top], [right,bottom]];
function inBox(point) {
var x=point[0], y=point[1];
return (leftBound<=x && x<=rightBound) && (topBound<=y && y<=bottomBound)
}
// overlap-based selection policy
// selects if one or more corners is in selection
return corners.some(inBox);
// overlap-based selection policy #2
// selects if any part of element is in selection
return corners.some(inBox) //|| ... slightly more complicated logic
// only-wholly-enclosed selection policy
// selects only if entire element is in selection
return corners.every(inBox);
})
$(".")
jQuery が不要な場合は、再帰コールバック ベースの DOM トラバーサルのお気に入りの方法に置き換えてください。