(函数($){
$.fn.ad = 函数(选项){
var lastScrollY= 0;
var czd = $(this);
var 设置= $.extend({
src:null,
closeSrc:null,
href:"#",
autoHide:true,
hideSecond:10,
位置: "顶部",
顶部:20,
底部:20,
布局:"左",
宽度:100,
高度:100,
不透明度:0.5,
设置位置:function(left, top){
return;
}
},选项 || {});
if(settings.src && settings.closeSrc){
var imgEl =“
";
var closeImgEl = "
";
$( this).append(imgEl closeImgEl);
$(this).css("position","absolute");
if(settings.position=='top'){
$ (this).css("top",settings.top "px");
} else {
$(this).css("bottom",settings.bottom "px");
}
$(this).css("opacity",settings.opacity);
$(this).css("filter","alpha(opacity=" parseInt(settings.opacity * 100) ")");
switch(settings.layout) {
case "left":
$(this).css("left","-100px");
休息;
case "right":
$(this).css("right","-100px");
休息;
case "center":
var left = (parseInt(window.screen.availWidth) - parseInt(settings.width))/2 "px";
$(this).css("left",left);
休息;
默认值:
$(this).css("left","-100px");
休息;
}
} else {
返回;
}
if(settings.autoHide) {
setTimeout("(function(){$('" $(this).selector "').hide();})() ;",parseInt(settings.hideSecond) * 1000;
}
//另外不同导致事件驱动不一样:scroll与onscroll
$(window).bind("scroll", function(){
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
diffY = document.documentElement.scrollTop;
else if (document.body)
diffY = document.body .scrollTop
else {
/*Netscape 内容*/
}
percent= 1 * (diffY - lastScrollY);
if(percent>0)
percent=Math.ceil(percent);
else
percent=Math.floor(percent);
if(settings.position=='top'){
var top = czd.css("top");
czd.css("top", parseInt(top) percent "px");
lastScrollY = percent;
} else {
var top = czd.css("bottom");
czd.css("bottom", parseInt(top) - percent "px");lastScrollY = percent;
}
});
}
})(jQuery);