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);
})
與您喜愛的遞歸基於回調的DOM遍歷的方法更換$(".")
如果你不想要的jQuery。
哪個瀏覽器? –
具體是android os web視圖。幸運的是,我有一個非常有限的特定範圍的目標。 – smokingoyster
噢,那是我的答案的三分之二,這對你沒有任何幫助:) –