* 一个基于jQuery的浮动广告的插件
调用示例1:
$(document).ready(function () {
    new $.floatAD({ renderTo: "floatDiv"});
});
调用示例2:
$(document).ready(function () {
    //初始化配置
    this.config = {
        renderTo: "floatDiv",
        //默认起始位置
        position:{
            x: 20,
            y: document.documentElement.clientHeight
        },
        //默认水平移动方向
        horizontalDirection:this.direction.right,
        //默认垂直移动方向
        verticalDirection:this.direction.up,
        //每次移动的位置
        moveSpace:1,
        //移动间隔,多少毫秒移动一次
        delay:30
    };
    new $.floatAD({ renderTo: "floatDiv"});
});
*/
(function ($) {
    /** config配置列表
    * renderTo:要呈现到的元素ID
    */
    $.floatAD = function (initConfig) {

//浮动方向
        this.direction =
        {
            up: "up",
            down: "down",
            left: "left",
            right: "right"
        };

//初始化配置
        this.config = {
            //默认起始位置
            position: {
                x: 20,
                y: document.documentElement.clientHeight
            },
            //默认水平移动方向
            horizontalDirection: this.direction.right,
            //默认垂直移动方向
            verticalDirection: this.direction.up,
            //每次移动的位置
            moveSpace: 1,
            //移动间隔,多少毫秒移动一次
            delay: 30
        };

$.extend(this.config, initConfig);
        $.extend(this, this.config);

//定时器
        this.interval;

this.container = $("#" + this.config.renderTo);
        this.container.css("position", "absolute")
        .css("top", this.position.y)
        .css("left", this.position.x);

this.screenWidth = $(window).width();
        this.screenHeight = $(window).height();
        this.containerWidth = this.container.outerWidth();
        this.containerHeight = this.container.outerHeight();

this.changePos = function () {
            this.container.css("left", this.position.x + $(document).scrollLeft());
            this.container.css("top", this.position.y + $(document).scrollTop());

//垂直方向移动
            if (this.verticalDirection == this.direction.down) {
                this.position.y = this.position.y + this.moveSpace;
            } else {
                this.position.y = this.position.y - this.moveSpace;
            }

//如果到达垂直边界,改变移动方向
            if (this.position.y <= 0) {
                this.verticalDirection = this.direction.down;
                this.position.y = 0;
            }
            else if (this.position.y >= (this.screenHeight - this.containerHeight)) {
                this.verticalDirection = this.direction.up;
                this.position.y = this.screenHeight - this.containerHeight;
            }

//水平方向移动
            if (this.horizontalDirection == this.direction.right) {
                this.position.x = this.position.x + this.moveSpace;
            } else {
                this.position.x = this.position.x - this.moveSpace;
            }

//如果到达水平边界,改变移动方向
            if (this.position.x <= 0) {
                this.position.x = 0;
                this.horizontalDirection = this.direction.right;
            }
            else if (this.position.x >= (this.screenWidth - this.containerWidth)) {
                this.position.x = this.screenWidth - this.containerWidth;
                this.horizontalDirection = this.direction.left;
            }
        }

this.start = function () {
            this.container.show();
            var me = this;
            this.interval = setInterval(function () {
                me.changePos();
            }, this.delay);
        }
        debugger
        this.start();
    }
})(jQuery)

jquery插件--浮动广告相关推荐

  1. html5自动提示插件,jquery万能浮动框提示插件

    特效描述:jquery 万能浮动框提示.jquery万能浮动框提示插件 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 jQuery万能浮动框插件测试 一.加载页面上元素 默认rel加 ...

  2. jQuery实现的浮动广告

    实现方法: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  3. jQuery:收集一些基于jQuery框架开发的控件/jquery插件2

    Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件. 主页:http://letmehaveblog.blogspot.com/2007/10/ ...

  4. 1000个JQuery插件(转载)

    超强1000个jquery极品插件!(转) 花N长时间积累的Jquery插件,希望大家喜欢.大家还有什么新的插件,请留言,我们一并收录. 感谢大家的支持. ++++++++++++++++++++++ ...

  5. Js浮动广告效果实现

    第一种 漂浮广告 不符合W3CJavaScript漂浮广告代码,很不错,代码精简,不过一次只有漂一个,复制就能用了.希望站长朋友喜欢. <html> <head> <ti ...

  6. 1000个jquery插件

    1.导航类 (1)Horizontal accordion: jQuery 基于jQuery开发,非常简单的水平方向折叠控件.二手图书 二手书 特价书 旧书网 (2)jQuery-Horizontal ...

  7. 你还不会创建jQuery插件 ?

    如何创建一个jQuery插件 为什么要创建jQuery插件 ? 因为这样代码可以复用. 我们有这样一个页面,页面上面有如下的文字(看源码),我们想要的效果是,当鼠标移到链接的时候,用一个浮动的div来 ...

  8. 【jQuery插件】用jQuery Masonry快速构建一个pinterest网站布局(转)

    [jQuery插件]用jQuery Masonry快速构建一个pinterest网站布局 时间:2011年03月21日作者:愚人码头查看次数:29,744 views评论次数:25条评论 前段时间领导 ...

  9. 2011年9月最新整理的10个有趣的jQuery插件集合

    这篇文章将整理出最有趣的jQuery10个插件集合,包括不同的插件,如滑块,用户界面​​对话框,图像过滤器等,对于喜欢把网页做得很炫很有创意的朋友,这些插件将是非常有帮助的. 1. Rotating ...

  10. 50个jQuery插件可将你的网站带到另一个高度

    Web领域一直在发生变化并且其边界在过去的每一天都在发生变化(甚至不能以小时为计),随着其边界的扩展取得了许多新发展.在这些进步之中,开发者的不断工作创造了更大和更好的脚本,这些脚本以插件方式带来更好 ...

最新文章

  1. V4L2获取usb视频流测试代码
  2. Web API 接口-JavaScript全部api接口文档
  3. 三星Exynos芯片只卖魅族?或是高通所致
  4. k8s StatefulSet
  5. Windows Security——获取Windows已经保存的WiFi网络密码
  6. Repeater在无数据记录时显示“无相关记录...”
  7. springboot mysql时区设置_java/springboot/mysql时区问题解决方案
  8. 卷积神经网络 手势识别_如何构建识别手语手势的卷积神经网络
  9. 如何实现Python调用C代码--python与C之间如何通信(swig)
  10. java InputStream读取数据问题【转】http://cuisuqiang.iteye.com/blog/1434416
  11. Day15Day16多任务和任务切换
  12. 微软MSDN,window10原版系统下载,操作系统msdn下载,microsoft office原版下载,www.msdn.itellyou.cn
  13. 诺顿5月17日病毒库更新后误杀系统文件导致系统蓝屏(STOP c000021a Unkown hard error)
  14. linux上卓懿应用商城王者荣耀键盘映射如何设置?
  15. java sqlldr_sqlldr使用(转)
  16. photoshop2019如何抠背景图
  17. MySQL慢查询,一口从天而降的锅!
  18. 玩转亚马逊 AWS IoT(3): SpringBoot 2.7 集成 AWS IoT 服务
  19. SpiceyPy-内核与时间尺度转换
  20. 弘辽科技:腾讯发力XR新业态有赞打通腾讯惠聚新增私域引流能力

热门文章

  1. 中国联通沃商-上海大学生手机应用创意、开发大赛活动
  2. 我的世界服务器插件文件夹,各位大神服务器没有插件文件夹怎么办
  3. 《Cocos Creator游戏实战》在游戏中显示弹幕
  4. Go 每日一库之 roaring
  5. 365地图java_中国气候区划在线地图(1:3200万)
  6. APP开发多少钱多少人和哪些注意事项
  7. python实验--文字小游戏(小黑屋)
  8. 树莓派Raspberry Pi 4b+实现摄像头拍照和实时监控
  9. 小武与YOLOv3 ---- 优图代码
  10. GSM/GPRS模组硬件电源设计指南