博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
回忆之浮窗
阅读量:7030 次
发布时间:2019-06-28

本文共 5086 字,大约阅读时间需要 16 分钟。

HTML

    
浮窗
width*1200
top left
top center
top right
center left
center center
center right
bottom left
bottom center
bottom right
返回
View Code

JS

/** * @description: 浮窗 * @author: jununx@gmail.com * @update: 2014/11/10 * * @param pos{string} 定位位置,可选 ['top left', 'top center', 'top right', 'center left', 'center center', 'center right', 'bottom left', 'bottom center', 'bottom right'] * @param screenWidth{number} 可选,贴近页面宽,例如:页面主体宽960,想让浮窗贴着主体对齐时设置这个宽度 * @param backTop{number|object} 如果有参数就表示这个对象或者里面的子元素有返回顶部,如果是number就表示speed,如果是object就给里面需要返回顶端功能的元素设置{'childClass': 'yourClassName', 'speed': number} */;(function($){    var methods = {        init: function(opts){            this.bindEvents(opts);        },        isIE6: function(){            return (!-[1,] && !window.XMLHttpRequest);        },        setPos: function(opts){            var win = $(window),                scrollLeft = this.isIE6() ? win.scrollLeft() : 0,                scrollTop = this.isIE6() ? win.scrollTop() : 0,                winW = win.width(),                winH = win.height(),                objW = opts.that.width(),                objH = opts.that.height(),                winHalfW = (winW - objW) / 2,                winHalfH = (winH - objH) / 2,                screenWidth = opts.screenWidth,                screenLeft = screenWidth ? (winW - screenWidth) / 2 - objW : 0,                screenRight = screenWidth ? (winW - screenWidth) / 2 + screenWidth : winW - objW,                pos = {                    'top left': {                        'top': scrollTop,                        'left': screenLeft                    },                    'top center': {                        'top': scrollTop,                        'left': winHalfW                    },                    'top right': {                        'top': scrollTop,                        'left': screenRight                    },                    'center left': {                        'top': winHalfH + scrollTop,                        'left': screenLeft                    },                    'center center': {                        'top': winHalfH + scrollTop,                        'left': winHalfW + scrollLeft                    },                    'center right': {                        'top': winHalfH + scrollTop,                        'left': screenRight                    },                    'bottom left': {                        'top': winH - objH + scrollTop,                        'left': screenLeft                    },                    'bottom center': {                        'top': winH - objH + scrollTop,                        'left': winHalfW + scrollLeft                    },                    'bottom right': {                        'top': winH - objH + scrollTop,                        'left': screenRight                    }                };            if(this.isIE6()){                opts.that.css('position', 'absolute').css(pos[opts.pos]);            }else{                opts.that.css('position', 'fixed').css(pos[opts.pos]);            }        },        bindEvents: function(opts){            var that = this;            $(window).on('load scroll resize', function(){                that.setPos(opts);            });            if (typeof opts.backTop === 'number') {                opts.that.on('click', function(){                    that.backTop(opts.backTop);                });            } else if (typeof opts.backTop === 'object') {                opts.that.find('.'+opts.backTop.childClass).on('click', function(){                    that.backTop(opts.backTop.speed);                });            }        },        backTop: function(speed){            $('html, body').animate({'scrollTop': 0}, speed);            return false;        }    };    $.fn.popup = function(opts){        opts = $.extend({            'that': this,            'pos': 'bottom right',            'screenWidth': 0,            'backTop': 0        }, opts || {});        methods.init(opts);        return this;    };})(jQuery);//use$('.t-l').popup({        'pos': 'top left',        'screenWidth': 1200    });    $('.t-c').popup({        'pos': 'top center',        'screenWidth': 1200    });    $('.t-r').popup({        'pos': 'top right',        'screenWidth': 1200    });    $('.c-l').popup({        'pos': 'center left',        'screenWidth': 1200    });    $('.c-c').popup({        'pos': 'center center',        'screenWidth': 1200    });    $('.c-r').popup({        'pos': 'center right',        'screenWidth': 1200    });    $('.b-l').popup({        'pos': 'bottom left',        'screenWidth': 1200    });    $('.b-c').popup({        'pos': 'bottom center',        'screenWidth': 1200    });    $('.b-r').popup({        'pos': 'bottom right',        'screenWidth': 1200,        'backTop': 400    });

 

转载于:https://www.cnblogs.com/jununx/p/4472910.html

你可能感兴趣的文章
程序简单的测试与升级(暨实践第一次作业)
查看>>
数据的奇偶校验
查看>>
java 应用程序的打包发行
查看>>
信号处理
查看>>
浏览器调用摄像头
查看>>
socket,tcp,http三者之间的区别和原理
查看>>
【100题】第五十九题 用C++编写不能被继承的类
查看>>
轻描淡写
查看>>
mysql基本操作
查看>>
39.CSS3弹性伸缩布局【下】
查看>>
[javascript]图解+注释版 Ext.extend()
查看>>
我的前端工具集(七)div背景网格
查看>>
linux 下mongo 基础配置
查看>>
【Dubbo实战】 Dubbo+Zookeeper+Spring整合应用篇-Dubbo基于Zookeeper实现分布式服务(转)...
查看>>
JUnit单元测试中的setUpBeforeClass()、tearDownAfterClass()、setUp()、tearDown()方法小结
查看>>
java之jvm学习笔记六(实践写自己的安全管理器)
查看>>
Docker容器查看ip地址
查看>>
在PC端或移动端应用中接入商业QQ
查看>>
将python3.6软件的py文件打包成exe程序
查看>>
DataTable 排序
查看>>