function FloatAd() { var obj = $("#w_rbox-1545792851165"); if (obj.find(".w_rbox").length == 0) return;//���û�����ݣ���ִ�� var windowHeight = $(window).height();//������߶� var windowWidth = $(window).width();//�������� var dirX = -1.5;//ÿ��ˮƽƯ�����򼰾���(��λ��px)���������ң������������Խ��Ļ��ͻῴ����Խ������������ijЩ����������ܻ���Ҫ����Ч�� var dirY = -1;//ÿ�δ�ֱƯ�����򼰾���(��λ��px)���������£��������ϣ����Խ��Ļ��ͻῴ����Խ������������ijЩ����������ܻ���Ҫ����Ч�� var delay = 30;//����ִ�е�ʱ��������λ���� obj.css({ left: windowWidth / 2 - obj.width() / 2 + "px", top: windowHeight / 2 - obj.height() / 2 + "px" });//��Ԫ�����ó���ҳ���м� obj.show();//Ԫ��Ĭ�������صģ�������һ�����ı�λ���Ӿ�ͻأ���ı�λ�ú�����ʾ���� var handler = setInterval(move, delay);//����ִ�У�����һ��ֵ�����ֵ��������ȡ����ִ�� obj.hover(function() {//��꾭��ʱ��ͣ���뿪ʱ���� clearInterval(handler);//ȡ����ִ�� }, function() { handler = setInterval(move, delay); }); obj.find(".close").click(function() {//�󶨹رհ�ť�¼� close(); }); $(window).resize(function() {//���ı䴰�ڴ�Сʱ�����»�ȡ�������С���Ա�֤�����磨Ʈ����������ӷ�Χ����Ư�ķ�ΧС���µĴ�С windowHeight = $(window).height();//������߶� windowWidth = $(window).width();//�������� }); function move() {//����ִ�еĺ���ʹԪ���ƶ� var currentPos = obj.position();//��ȡ��ǰλ�ã�����JQuery�ĺ�������http://hemin.cn/jq/position.html var nextPosX = currentPos.left + dirX;//��һ��ˮƽλ�� var nextPosY = currentPos.top + dirY;//��һ����ֱλ�� if (nextPosX <= 0 || nextPosX >= windowWidth - obj.width()) {//���ﵽ��ߣ����ߴﵽ�ұߣ���ı�Ϊ�෴���� dirX = dirX * -1;//�ı䷽�� nextPosX = currentPos.left + dirX;//Ϊ�˲���磬���»�ȡ��һ��λ�� } if (nextPosY <= 0 || nextPosY >= windowHeight - obj.height() - 5) {//���ﵽ�ϱߣ����ߴﵽ�±ߣ���ı�Ϊ�෴���� dirY = dirY * -1;//�ı䷽�� nextPosY = currentPos.top + dirY;//Ϊ�˲���磬���»�ȡ��һ��λ�� } obj.css({ left: nextPosX + "px", top: nextPosY + "px" });//�ƶ�����һ��λ�� } function close() {//ֹͣƯ���������Ư������ clearInterval(handler); obj.remove(); } } FloatAd("#floadAD");//����