function getmysrc() {
var scriptsrc = document.getelementsbytagname('script')[document.getelementsbytagname('script').length - 1].src;
return scriptsrc;
}
var url = getmysrc();
$(function () {
$.ajax({
url: "/sitead/floatimg",
type: "post",
datatype: "json",
data: {count: 4 },
success: function (result) {
if (result.code==0) {
$.each(result.data, function (i) {
showad(result.data[i]);
});
}
},
error: function (e) {
}
});
});
function showad(ad) {
var img = "";
var imgstyle = "";
if (ad.imagewidth > 0 && ad.imageheight > 0) {
imgstyle = "width:" + ad.imagewidth + "px;height:" + ad.imageheight + "px;max-width:initial;max-height:initial;";
}
else {
imgstyle = "max-width:initial;max-height:initial;";
}
var _content;
if (ad.customtext) {
var _contentstyle = "display:inline-block;font-size:16px;color:red;";
if (ad.imageheight > 0) {
_contentstyle += "padding:" + ad.imageheight / 2 + "px 0;";
} else {
_contentstyle += "padding:23px 0;";
}
if (ad.imagewidth > 0) {
_contentstyle += "width:" + ad.imagewidth + "px;";
} else {
_contentstyle += "width:300px;";
}
_content = '
';
}
else {
_content = '';
}
if (ad.link != "" && ad.links != "javascript:;") {
img = '' + _content + '';
}
else {
img = _content;
}
if (ad.fixed == 0) {//漂浮
var addom = $('');
addom.append('');
addom.find(".ad_close").click(function () {
addom.remove();
});
$("body").append(addom);
var runad = new admove(ad.id);
runad.run();
}
else {
var style = "position: fixed;";
if (ad.pos == 0) {
style += "top:" + ad.offsety + "px;left:" + ad.offsetx + "px;";
}
else if (ad.pos == 1) {
style += "top:" + ad.offsety + "px;right:" + ad.offsetx + "px;";
}
else if (ad.pos == 2) {
style += "bottom:" + ad.offsety + "px;right:" + ad.offsetx + "px;";
}
else {
style += "bottom:" + ad.offsety + "px;left:" + ad.offsetx + "px;";
}
var div = $('');
div.find(".ad_close").click(function () {
div.remove();
});
$("body").append(div);
}
}
function getquerystring(name, url) {
var query = url.split("?")[1];
var queryarr = query.split("&");
var result = "";
//queryarr.foreach(function (item) {
// var obj = {};
// var value = item.split("=")[1];
// var key = item.split("=")[0];
// if (key == name) {
// result = value;
// }
//});
$.each(queryarr, function (index,item) {
var obj = {};
var value = item.split("=")[1];
var key = item.split("=")[0];
if (key == name) {
result = value;
}
});
return result;
}
function addevent(obj, evttype, func, cap) {
cap = cap || false;
if (obj.addeventlistener) {
obj.addeventlistener(evttype, func, cap);
return true;
} else if (obj.attachevent) {
if (cap) {
obj.setcapture();
return true;
} else {
return obj.attachevent("on" + evttype, func);
}
} else {
return false;
}
}
function getpagescroll() {
var xscroll, yscroll;
if (self.pagexoffset) {
xscroll = self.pagexoffset;
} else if (document.documentelement && document.documentelement.scrollleft) {
xscroll = document.documentelement.scrollleft;
} else if (document.body) {
xscroll = document.body.scrollleft;
}
if (self.pageyoffset) {
yscroll = self.pageyoffset;
} else if (document.documentelement && document.documentelement.scrolltop) {
yscroll = document.documentelement.scrolltop;
} else if (document.body) {
yscroll = document.body.scrolltop;
}
arraypagescroll = new array(xscroll, yscroll);
return arraypagescroll;
}
function getpagesize() {
var xscroll, yscroll;
if (window.innerheight && window.scrollmaxy) {
xscroll = document.body.scrollwidth;
yscroll = window.innerheight + window.scrollmaxy;
} else if (document.body.scrollheight > document.body.offsetheight) {
xscroll = document.body.scrollwidth;
yscroll = document.body.scrollheight;
} else {
xscroll = document.body.offsetwidth;
yscroll = document.body.offsetheight;
}
var windowwidth, windowheight;
if (self.innerheight) {
windowwidth = self.innerwidth;
windowheight = self.innerheight;
} else if (document.documentelement && document.documentelement.clientheight) {
windowwidth = document.documentelement.clientwidth;
windowheight = document.documentelement.clientheight;
} else if (document.body) {
windowwidth = document.body.clientwidth;
windowheight = document.body.clientheight;
}
if (yscroll < windowheight) {
pageheight = windowheight;
} else {
pageheight = yscroll;
}
if (xscroll < windowwidth) {
pagewidth = windowwidth;
} else {
pagewidth = xscroll;
}
arraypagesize = new array(pagewidth, pageheight, windowwidth, windowheight)
return arraypagesize;
}
var admoveconfig = new object();
admoveconfig.isinitialized = false;
admoveconfig.scrollx = 0;
admoveconfig.scrolly = 0;
admoveconfig.movewidth = 0;
admoveconfig.moveheight = 0;
admoveconfig.resize = function () {
var winsize = getpagesize();
admoveconfig.movewidth = winsize[2];
admoveconfig.moveheight = winsize[3];
admoveconfig.scroll();
}
admoveconfig.scroll = function () {
var winscroll = getpagescroll();
admoveconfig.scrollx = winscroll[0];
admoveconfig.scrolly = winscroll[1];
}
addevent(window, "resize", admoveconfig.resize);
addevent(window, "scroll", admoveconfig.scroll);
function admove(id) {
if (!admoveconfig.isinitialized) {
admoveconfig.resize();
admoveconfig.isinitialized = true;
}
var obj = document.getelementbyid(id);
obj.style.position = "absolute";
var w = admoveconfig.movewidth - obj.offsetwidth;
var h = admoveconfig.moveheight - obj.offsetheight;
var x = w * math.random(), y = h * math.random();
var rad = (math.random() + 1) * math.pi / 6;
var kx = math.sin(rad), ky = math.cos(rad);
var dirx = (math.random() < 0.5 ? 1 : -1), diry = (math.random() < 0.5 ? 1 : -1);
var step = 1;
var interval;
this.setlocation = function (vx, vy) { x = vx; y = vy; }
this.setdirection = function (vx, vy) { dirx = vx; diry = vy; }
obj.custommethod = function () {
obj.style.left = (x + admoveconfig.scrollx) + "px";
obj.style.top = (y + admoveconfig.scrolly) + "px";
rad = (math.random() + 1) * math.pi / 6;
w = admoveconfig.movewidth - obj.offsetwidth;
h = admoveconfig.moveheight - obj.offsetheight;
x = x + step * kx * dirx;
if (x < 0) { dirx = 1; x = 0; kx = math.sin(rad); ky = math.cos(rad); }
if (x > w) { dirx = -1; x = w; kx = math.sin(rad); ky = math.cos(rad); }
y = y + step * ky * diry;
if (y < 0) { diry = 1; y = 0; kx = math.sin(rad); ky = math.cos(rad); }
if (y > h) { diry = -1; y = h; kx = math.sin(rad); ky = math.cos(rad); }
}
this.run = function () {
var delay = 10;
interval = setinterval(obj.custommethod, delay);
obj.onmouseover = function () { clearinterval(interval); }
obj.onmouseout = function () { interval = setinterval(obj.custommethod, delay); }
}
}