(function ($) {
$.fn.floatad = function (options) {
var defaults = {
imgsrc: "#", //漂浮图片路径
url: "#", //图片点击跳转页
openstyle: 1, //跳转页打开方式 1为新页面打开 0为当前页打开
speed: 10, //漂浮速度 单位毫秒
title: "",
width: 0,
height: 0
};
var options = $.extend(defaults, options);
var _target = options.openstyle == 1 ? "target='_blank'" : '';
var _title = options.title == "" ? "" : ' alt="' + options.title + '" title="' + options.title + '" ';
var html = "
";
html += "
";
html += "
关闭
";
html += "
";
$('body').append(html);
function init() {
var x = 0, y = 0
var xin = true, yin = true
var step = 1
var delay = 10
var obj = $("#float_ad")
obj.find('img.float_ad_img').load(function () {
var float = function () {
var l = t = 0;
var ow = obj.width(); //当前广告的宽
var oh = obj.height(); //高
var dw = $(window).width(); //浏览器窗口的宽
var dh = $(window).height();
x = x + step * (xin ? 1 : -1);
if (x < l) {
xin = true; x = l
}
if (x > dw - ow - 1) {//-1为了ie
xin = false; x = dw - ow - 1
}
y = y + step * (yin ? 1 : -1);
if (y > dh - oh - 1) {
yin = false; y = dh - oh - 1;
}
if (y < t) {
yin = true; y = t
}
var left = x;
var top = y;
obj.css({ 'top': top, 'left': left });
}
var itl = setinterval(float, options.speed);
$('#float_ad').mouseover(function () { clearinterval(itl) });
$('#float_ad').mouseout(function () { itl = setinterval(float, options.speed) })
});
// 点击关闭
$('#close_float_ad').click(function () {
$('#float_ad').hide();
});
}
init();
}; //floatad
})(jquery);