1

次のコードを使用しているスクリプトでは、ポップアップウィンドウを画面の中央に配置するために使用されます。

Yクリックした項目と位置が同じになるように、これを変更する必要があります。そのため、アイテムをクリックすると、クリックしたアイテムと同じ高さにポップアップが表示されます。私はjqueryについての手がかりがなく、2時間試しても役に立ちませんでした。任意の助けをいただければ幸いです

編集が必要な行をマークしました。

                switch(a)
            {
                case 'postdetails':
                case 'userdetails':
                    $('#reputation-popup').addClass('normal-popup');
                    targetleft = ($(window).width() - $('#reputation-popup').outerWidth()) / 2;
                    targettop = ($(window).height() - $('#reputation-popup').outerHeight()) / 2;
                    /////// THE LINE ABOVE THIS IS THE ONE I NEED TO EDIT!!!! //////////

                break;
                case 'newpopup':
                    $('#reputation-popup').addClass('new-popup');
                    targetleft = ($(window).width() - $('#reputation-popup').outerWidth()) / 2;
                    targettop = ($(window).height() - $('#reputation-popup').outerHeight()) / 2;
                break;
                default:
                    $('#reputation-popup').addClass('small-popup');
                    // Center popup relative to clicked coordinate
                    targetleft = c.pageX - $('#reputation-popup').outerWidth() / 2;
                    // Popup can not be too close or behind the right border of the screen
                    targetleft = Math.min (targetleft, $(document).width() - 20 - $('#reputation-popup').outerWidth());
                    targetleft = Math.max (targetleft, 20);
                    targettop = c.pageY + 10;
                break;
            }
4

3 に答える 3

1

で試してください:

 $("item").offset().top;
 $("item").offset().left;

詳細はこちら: http://api.jquery.com/offset/

于 2013-08-11T10:42:25.030 に答える
1

次の jQuery 関数を使用して、ポップアップ メニューを配置できます。

1) event.pageX、event.pageY は、ドキュメントに対するマウスの位置を示します。

参照: http://api.jquery.com/event.pageY/

2) offset() : 要素のオフセット位置を与える

参照: http://api.jquery.com/offset/

3) position() : 要素の相対的な位置を示します

参考:http ://api.jquery.com/position/

于 2013-08-11T10:46:38.583 に答える