自己写的jQuery浮动广告插件
效果图:

文件位置摆放:

插件的js代码:
$.extend({
pfAdv:function(options){
var defaults={
count:1,
startTop:200,
startLeft:200,
width:140,//ͼƬС
height:180,
imageSrc:"pfAdvPic.jpg",
step:1,
delay:30,
idStr:"pfAdv"
}
options= $.extend(defaults,options);
var html="";
html+="<div id="+options.idStr+" class='pfAdv'>";
html+="<div class='plCloseDiv'></div>";
html+="<div><img src="+options.imageSrc+"></div>";
html+="</div>";
$("body").append(html);//html
var advBoxObj=$("#"+options.idStr);//
advBoxObj.css({"position":"absolute","z-index":998}).width(options.width).height(options.height);//涨λ
$("img",advBoxObj).width(options.width).height(options.height);
var advH=advBoxObj.outerHeight();//ĸ߶
var advW=advBoxObj.outerWidth();//Ŀ
var advMaxTop=0;//top
var advMaxLeft=0;//left
var stepMashionX=1;//1,ʾˮƽstep,-1ʾˮƽstep
var stepMashionY=1;//1,ʾֱstep,-1ʾֱstep
var currentX=0;//ǰλ
var currentY=0;
var divToBrowTop=options.startTop;
var divToBrowLeft=options.startLeft;
function getScroll(){
var scrollTop=$(window).scrollTop();//뿪߶
var scrollLeft=$(window).scrollLeft();//
return {x:scrollLeft,y:scrollTop};
}
function move(){
var browW=$(window).width();//
var browH=$(window).height();//߶
var scroll=getScroll();
currentX=divToBrowLeft+scroll.x;//top
currentY=divToBrowTop+scroll.y;//left
advMaxTop=browH-advH+scroll.y;//top,
advMaxLeft=browW-advW+scroll.x;//left,
if(currentY>=advMaxTop){
stepMashionY=-1;
currentY=divToBrowTop-options.step;
}
else if(currentY>scroll.y&¤tY<advMaxTop){
if(stepMashionY==-1)
currentY=divToBrowTop-options.step;
else if(stepMashionY==1)
currentY=divToBrowTop+options.step;
else alert("ֱϵstepMashionY");
}
else if(currentY<=scroll.y){
stepMashionY=1;
currentY=divToBrowTop+options.step;
}
else {
alert("ֱϱȽ");
}
if(currentX>=advMaxLeft){
stepMashionX=-1;
currentX=divToBrowLeft-options.step;
}
else if(currentX>scroll.x&¤tX<advMaxLeft){
if(stepMashionX==-1){
currentX=divToBrowLeft-options.step;
}
else if(stepMashionX==1){
currentX=divToBrowLeft+options.step;
}
else alert("ˮƽϵstepMashionX")
}
else if(currentX<=scroll.x){
stepMashionX=1;
currentX=divToBrowLeft+options.step;
}
else {
alert("ˮƽϱȽ");
}
divToBrowLeft=currentX;
divToBrowTop=currentY;
//var scroll=getScroll();
currentX+=scroll.x;
currentY+=scroll.y;
advBoxObj.css({top:currentY+"px",left:currentX+"px"});
}
$(".plCloseDiv",advBoxObj).on("click",function(){advBoxObj.remove()})
//$(window).resize(function(){initNum();});
var moveMashion=null;
advBoxObj.bind("mouseover",function(){clearTimeout(moveMashion);}).bind("mouseleave",function(){moveMashion=setInterval(move,options.delay);})
moveMashion=setInterval(move,options.delay);
move();
}
});
css代码:
.pfAdv{ }
.plCloseDiv{ width:16px; height:16px; background-image:url(pfAdvPicClose.jpg); background-repeat:no-repeat; position:absolute; top:; right:; cursor:pointer;}
.plCloseA{ color:#102a49; font-size:14px; font-family:""; text-decoration:none; }
插件的调用:
$(function(){
$.pfAdv({});
})
自己写的jQuery浮动广告插件的更多相关文章
- jQuery 浮动标签插件,帮助你提升表单用户体验
浮动标签模式(Float Label Pattern)是最新流行的一种表单输入域的内容提示方式,当用户在输入框输入内容的时候,原先占位符的内容向上移动,显示在输入的内容的上面.这里推荐的这款 jQue ...
- 自己写的一个jQuery对联广告插件
效果图: 文件的位置摆放: 插件的代码: ;(function($){ $.extend({ dLAdv:function(options){ var defaults={ leftType:0,// ...
- 亲手用模块化方式写一个jquery QQ表情插件。
在回复或是评论的时候,很多时间都需要有回复表情的功能,然后而需要插入QQ表情可以是最常见的. 插件也写多很多个了,这次写插件就下了一个决定.就是使用模块化来开发. 最后在我的源代码中有这样子一段: v ...
- JQuery浮动对象插件
写了个插件,用来固定表的头部和尾部. /*! * smartFloat v1.0.1 * Copyright 2019- Richard * Licensed under MIT */ $.fn.ex ...
- 自己写的jquery 弹框插件
html部分 <!DOCTYPE html> <html> <head lang="en"> <meta charset="UT ...
- 非常强大的jQuery万能浮动框插件
支持hover, click, focus以及无事件触发:支持多达12种位置的定位,出界自动调整:支持页面元素加载,Ajax加载,下拉列表,提示层效果,tip类效果等:可自定义装载容器:内置UI不错的 ...
- jQuery手风琴广告展示插件
效果说明:当鼠标移动到已折叠广告的标题后,折叠当前已展开的广告,并同步展开相应的折叠广告.这种Accordion效果,看似简单,但因为存在动画同步的问题,不能简单地用两个animate()来实现.必须 ...
- 用jQuery写了一个模态框插件
用jQuery写了一个模态框插件 大家觉得下面的框框好看么, 水印可以去掉(这个任务交给你们了(- o -)~zZ); "info"框 $("div").con ...
- 自己写的一个jQuery轮播插件
大概是四月初开始写的,中间停了有一个月吧.这是我在Github的第一个项目.项目地址:https://github.com/linzb93/jquery.slide.js. 轮播应该是最好写的插件了, ...
随机推荐
- Swift中格式化日期
Swift语言中格式化日期跟其它编程语言很相似: var dformatter = NSDateFormatter() dformatter.dateFormat = "yyyy年MM月dd ...
- OK335xS Linux Qt make: icpc: Command not found
OK335xS Linux Qt make: icpc: Command not found 一.出错现象: make: icpc: Command not found make: *** [main ...
- BZOJ4310: 跳蚤 【后缀数组+二分】
Description 很久很久以前,森林里住着一群跳蚤.一天,跳蚤国王得到了一个神秘的字符串,它想进行研究.首先,他会把串 分成不超过 k 个子串,然后对于每个子串 S,他会从S的所有子串中选择字典 ...
- codeforces 724c Ray Tracing
好题 原题: There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is ...
- 系统有专门画图的api
- Dataframe 取列名
1.[column for column in df] 2.df.columns.values 返回 array 3.list(df) 4.df.columns 返回Index,可以通过 tolist ...
- IP地址 无限网卡的MAC地址
- java安全性-引用-分层-解耦
Java不支持指针, 一切对内存的访问都必须通过对象的实例变量来实现,这样就防止程序员使用 "特洛伊"木马等欺骗手段访问对象的私有成员 访问一个对象必须通过这个对象的引用 java ...
- Gitserver代理上网安装出现故障的几个解决的方法。
1.gem安装出现以下错误 root@ubuntu:/home/git/gitlab# sudo gem install bundler --no-ri --no-rdoc ERROR: Could ...
- php过滤html标签截取部分内容
<?php $str = '<span>fdsfsdf</span><a href="#">href</a>'; echo h ...