中国开发网: 论坛: 程序员情感CBD: 贴子 695010
dead_lee: 不过看了下news.163.com的页面, 还好啊
有个floatad.js
里面写得蛮规矩的

var fade_away_hide = false;
var TimeToFade = 2000.0;
var pagechoice_float_ad_hide_timeout = 15000;

var _inner_browser_width = 0;
var _inner_browser_height = 0;
var _browser_scroll_x = 0;
var _browser_scroll_y = 0;
var _scroll_interval = null;
var _pagechoice_float_div_is_hiding = false;
var pagechoice_agt=navigator.userAgent.toLowerCase();
var pagechoice_isie = ((pagechoice_agt.indexOf("msie") != -1)
&& (pagechoice_agt.indexOf("opera") == -1)
&& (pagechoice_agt.indexOf("omniweb") == -1));


function calc_window_size()
{
if( typeof( window.innerWidth ) == 'number' )
{
//Non-IE
_inner_browser_width = window.innerWidth;
_inner_browser_height = window.innerHeight;
}
else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
{
//IE 6+ in 'standards compliant mode'
_inner_browser_width = document.documentElement.clientWidth;
_inner_browser_height = document.documentElement.clientHeight;
}
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
{
//IE 4 compatible
_inner_browser_width = document.body.clientWidth;
_inner_browser_height = document.body.clientHeight;
}
}

function calc_scroll_xy()
{
_browser_scroll_x = 0;
_browser_scroll_y = 0;
if( typeof( window.pageYOffset ) == 'number' )
{
//Netscape compliant
_browser_scroll_y = window.pageYOffset;
_browser_scroll_x = window.pageXOffset;
} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
{
//DOM compliant
_browser_scroll_y = document.body.scrollTop;
_browser_scroll_x = document.body.scrollLeft;
}
else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
{
//IE6 standards compliant mode
_browser_scroll_y = document.documentElement.scrollTop;
_browser_scroll_x = document.documentElement.scrollLeft;
}
}

function pagechoice_float_div_scroll()
{
calc_window_size();
calc_scroll_xy();

var float_div = document.getElementById("pagechoice_float_div");

if (typeof pagechoice_float_win_auto_scroll_y == 'undefined')
pagechoice_float_win_auto_scroll_y = true;

if (typeof pagechoice_float_win_offset_x == 'undefined')
pagechoice_float_win_offset_x = 5;

pagechoice_float_win_offset_fix = 0;
if (!pagechoice_isie)
pagechoice_float_win_offset_fix = 17;

if (typeof pagechoice_float_win_offset_y == 'undefined')
pagechoice_float_win_offset_y = 5;

if (typeof pagechoice_float_win_align != 'undefined' && pagechoice_float_win_align == 'topleft')
{
float_div.style.left = _browser_scroll_x + pagechoice_float_win_offset_x + 'px';
float_div.style.top = pagechoice_float_win_auto_scroll_y ?
((pagechoice_float_win_offset_y + _browser_scroll_y) + 'px') : (pagechoice_float_win_offset_y + 'px') ;
float_div.style.width = pagechoice_float_win_width + 'px';
float_div.style.height = pagechoice_float_win_height + 'px';
}
else if (typeof pagechoice_float_win_align != 'undefined' && pagechoice_float_win_align == 'topright')
{
float_div.style.left = (_browser_scroll_x + _inner_browser_width
- pagechoice_float_win_width - pagechoice_float_win_offset_x - pagechoice_float_win_offset_fix) + 'px';
float_div.style.top = pagechoice_float_win_auto_scroll_y ?
((pagechoice_float_win_offset_y + _browser_scroll_y) + 'px') : (pagechoice_float_win_offset_y + 'px');
float_div.style.width = pagechoice_float_win_width + 'px';
float_div.style.height = pagechoice_float_win_height + 'px';
}
else if (typeof pagechoice_float_win_align != 'undefined' && pagechoice_float_win_align == 'bottomleft')
{
float_div.style.left = (_browser_scroll_x + pagechoice_float_win_offset_x) + 'px';
float_div.style.top = pagechoice_float_win_auto_scroll_y ?
((_browser_scroll_y + _inner_browser_height - pagechoice_float_win_height - pagechoice_float_win_offset_y) + 'px')
: (( _inner_browser_height - pagechoice_float_win_height - pagechoice_float_win_offset_y)+ 'px');
float_div.style.width = pagechoice_float_win_width + 'px';
float_div.style.height = pagechoice_float_win_height + 'px';
}
else
{

float_div.style.left = (_browser_scroll_x + _inner_browser_width
- pagechoice_float_win_width - pagechoice_float_win_offset_x - pagechoice_float_win_offset_fix) + 'px';
float_div.style.top = pagechoice_float_win_auto_scroll_y ?
((_browser_scroll_y + _inner_browser_height - pagechoice_float_win_height - pagechoice_float_win_offset_y) + 'px')
: (( _inner_browser_height - pagechoice_float_win_height - pagechoice_float_win_offset_y)+ 'px');
float_div.style.width = pagechoice_float_win_width + 'px';
float_div.style.height = pagechoice_float_win_height + 'px';
}
}

function fade(eid)
{
var element = document.getElementById(eid);
if(element == null)
return;

if(element.FadeState == null)
{
if(element.style.opacity == null
|| element.style.opacity == ''
|| element.style.opacity == '1')
{
element.FadeState = 2;
}
else
{
element.FadeState = -2;
}
}

if(element.FadeState == 1 || element.FadeState == -1)
{
element.FadeState = element.FadeState == 1 ? -1 : 1;
element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
}
else
{
element.FadeState = element.FadeState == 2 ? -1 : 1;
element.FadeTimeLeft = TimeToFade;
setTimeout("animateFade(" + new Date().getTime()
+ ",'" + eid + "')", 33);
}
}

function animateFade(lastTick, eid)
{
var curTick = new Date().getTime();
var elapsedTicks = curTick - lastTick;

var element = document.getElementById(eid);

if(element.FadeTimeLeft <= elapsedTicks)
{
element.style.opacity = element.FadeState == 1 ? '1' : '0';
element.style.filter = 'alpha(opacity = '
+ (element.FadeState == 1 ? '100' : '0') + ')';
element.FadeState = element.FadeState == 1 ? 2 : -2;
if (element.FadeState == -2)
{
pagechoice_float_ad_real_hide();
}
return;
}

element.FadeTimeLeft -= elapsedTicks;
var newOpVal = element.FadeTimeLeft/TimeToFade;
if(element.FadeState == 1)
newOpVal = 1 - newOpVal;

element.style.opacity = newOpVal;
element.style.filter =
'alpha(opacity = ' + (newOpVal*100) + ')';

setTimeout("animateFade(" + curTick
+ ",'" + eid + "')", 33);
}

function pagechoice_float_ad_display()
{
document.getElementById("pagechoice_float_div").style.display="block";
if (typeof pagechoice_float_ad_hide_timeout != "undefined")
setTimeout ( "pagechoice_float_ad_hide()", pagechoice_float_ad_hide_timeout);
_scroll_interval = setInterval("pagechoice_float_div_scroll()", 50);
}

function pagechoice_float_ad_hide()
{
if (_pagechoice_float_div_is_hiding)
return;
_pagechoice_float_div_is_hiding = true;
if (fade_away_hide)
setTimeout("fade('pagechoice_float_div')", 200);
else
pagechoice_float_ad_real_hide();
}

function pagechoice_float_ad_real_hide()
{
var float_div = document.getElementById("pagechoice_float_div");
float_div.style.left = -2000 + 'px';
float_div.style.top = -2000 + 'px';
float_div.style.width = 1 + 'px';
float_div.style.height = 1 + 'px';
if (_scroll_interval)
clearInterval(_scroll_interval);
}

function pagechoice_float_ad_create()
{
calc_window_size();
calc_scroll_xy();

window.onerror = null;
var pagechoice_style_str="";

var pagechoice_doc_str = "";
if (pagechoice_float_ad_is_flash)
{
pagechoice_doc_str =
'<div id="pagechoice_float_div" style="'
+ 'POSITION: ABSOLUTE;'
+ 'WIDTH: ' + pagechoice_float_win_width + 'px;'
+ 'HEIGHT: ' + pagechoice_float_win_height + 'px;'
+ 'Z-INDEX:99999; DISPLAY: none; ">'
+ '<div id="pc_flashcontent_float">ads here</div>'
+ '</div>'
+ '<scr' + 'ipt language="javascript">'
+ pagechoice_float_ad_str
+ '</scr' + 'ipt>';
}
else
{
pagechoice_doc_str =
'<div id="pagechoice_float_div" style="'
+ 'POSITION: ABSOLUTE;'
+ 'WIDTH: ' + pagechoice_float_win_width + 'px;'
+ 'HEIGHT: ' + pagechoice_float_win_height + 'px;'
+ 'Z-INDEX:99999; DISPLAY: none; ">'

+ pagechoice_float_ad_str
+ '</div>';

}
if (pagechoice_float_ad_pub_tracking)
{
if (pagechoice_float_ad_pub_tracking_type == 'html')
{
pagechoice_doc_str = pagechoice_doc_str
+ '<div id="publisher_float_ad_trace" style="'
+ 'POSITION: ABSOLUTE;'
+ 'WIDTH: 1px;'
+ 'HEIGHT: 1px;'
+ 'LEFT: -2px;'
+ 'TOP: -2px;'
+ 'Z-INDEX:99999; DISPLAY: none; ">'
+ unescape(pagechoice_float_ad_pub_tracking_script)
+ '</div>';
}
}

if (pagechoice_float_ad_adv_tracking)
{
if (pagechoice_float_ad_adv_tracking_type == 'html')
{
pagechoice_doc_str = pagechoice_doc_str
+ '<div id="advertiser_float_ad_trace" style="'
+ 'POSITION: ABSOLUTE;'
+ 'WIDTH: 1px;'
+ 'HEIGHT: 1px;'
+ 'LEFT: -4px;'
+ 'TOP: -4px;'
+ 'Z-INDEX:99999; DISPLAY: none; ">'
+ unescape(pagechoice_float_ad_adv_tracking_script)
+ '</div>';
}
}

document.write(pagechoice_doc_str);
pagechoice_float_div_scroll();
}

if (pagechoice_display_float_ad)
{
pagechoice_float_ad_create();
if (pagechoice_float_ad_load_complete)
setTimeout ( "pagechoice_float_ad_display()", 100);
}

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录