I've just written a plugin which implements this feature. Fiddle: http://jsfiddle.net/FJ5Cp/1/
関数ロジックは以下のようになります。
- 現在の要素の左位置とオフセット幅を取得します。これらを一緒に追加して、右の枠線を取得します。
- 各要素の左の位置と幅のオフセットを取得し、これらを追加して右の境界線を取得します。この値と1との値を比較してください。
使用法と機能:
// Basic usage
var allRightElements = $("element").rightOfCurrent();
// Only select ___ elements which are located right of the current element
var allRightElementsFilter = $("element").rightOfCurrent("___");
// Only select ___ elements, which are located right of the current element,
// which are childs of ####
var allRightFilterInsideSomething = $("element").rightOfCurrent("___", "###");
(function($){
$.fn.rightOfCurrent = function(selector, context){
elem = this.eq(0);
selector = selector || '*';
context = context || null;
var currentRight = elem.offset().left + elem.width();
return $(selector, context).filter(function(){
var $this = $(this);
if ($this.css('position') == 'absolute'){
return $this.offset().left + $this.width() > currentRight;
}
return false;
});
}
})(jQuery);