久不出技术类文章,我都忘了自己是一程序员啦......今天写一点工作中遇到的东西,大家共同学习,反正也比较浅显了。
在安图等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站建设、网站建设 网站设计制作按需求定制制作,公司网站建设,企业网站建设,品牌网站建设,营销型网站建设,成都外贸网站建设公司,安图网站建设费用合理。
弹出窗口
我们在工作中,经常会碰到弹出窗口类应用,有时候还需要一点遮盖层:
这类圆角弹出框其实用得还是很广泛的,用CSS3可以很容易的出现,但是考虑到浏览器兼容问题,这类还是需要用图片实现了
主要代码如下:
- //弹出层剧中
- function popup(popupName) {
- var _scrollHeight = $(document).scrollTop(); //获取当前窗口距离页面顶部高度
- _windowHeight = $(window).height(); //获取当前窗口高度
- _windowWidth = $(window).width(); //获取当前窗口宽度
- _popupHeight = popupName.height(); //获取弹出层高度
- _popupWeight = popupName.width(); //获取弹出层宽度
- // _posiTop = (_windowHeight - _popupHeight) / 2 + _scrollHeight - 50;
- _posiTop = _scrollHeight + 120;
- _posiLeft = (_windowWidth - _popupWeight) / 2;
- popupName.css({ "left": _posiLeft + "px", "top": _posiTop + "px", "display": "block" }); //设置position
- }
- function dragFunc(dragDiv, dragBody) {
- if (dragDiv[0] && dragBody[0]) {
- var dragAble = false;
- var x1 = 0;
- var y1 = 0;
- var l = 0;
- var t = 0;
- var divOffset = dragBody.offset();
- dragDiv.mousedown(function (e) {
- var ss = this;
- // var rootId =
- dragDiv.css("cursor", "move");
- dragAble = true;
- // 当前鼠标距离div边框的距离
- // 当前鼠标坐标,减去div相对左边的像素
- l = parseInt(dragBody.css("left"));
- t = parseInt(dragBody.css("top"));
- x1 = e.clientX - l;
- y1 = e.clientY - t;
- x1x1 = x1 > 0 ? x1 : 0;
- y1y1 = y1 > 0 ? y1 : 0;
- this.setCapture && this.setCapture();
- });
- dragDiv.mousemove(function (e) {
- if (!dragAble)
- return;
- // 当前div左边的坐标
- // 当前鼠标坐标,减去鼠标拖动量
- var x2 = 0;
- var y2 = 0;
- //需要考虑滚动条问题!!!
- var top = $(document).scrollTop() ? $(document).scrollTop() - 15 : 0;
- var left = $(document).scrollLeft() ? $(document).scrollLeft() - 15 : 0;
- x2 = e.clientX - x1 + left;
- y2 = e.clientY - y1 + top;
- x2x2 = x2 > 0 ? x2 : 0;
- y2y2 = y2 > 0 ? y2 : 0;
- //要移动一定数量才移动
- if (Math.abs(l - x2) > 10 || Math.abs(t - y2) > 10) {
- dragBody.css("left", x2 + "px");
- dragBody.css("top", y2 + "px");
- }
- });
- dragDiv.mouseup(function (event) {
- if (!dragAble)
- return;
- dragAble = false;
- // dragDiv.css("position", "relative");
- this.releaseCapture && this.releaseCapture();
- });
- }
- }
- var MyDialog = function (cfg) {
- this.config = {
- id: (new Date()).getTime().toString(),
- el: null,
- bodyId: null,
- cover: true,
- boxHtm: '
' +- ' ' +
- '
' + - '
' + - ' ' +
- '
' + - ' ' +
- '
' + - ' ' +
- ' ' +
- '
' +- '
' + - '
' +- ' ' +
- '
' + - '
' +- '
' +
- ' 请输入标题 ' +
- ' ' +
- ' ' +
- '
' +- ' 请输入内容 ' +
- ' ' +
- ' ' +
- '
' + - ' ' +
- '
' +- '
' + - '
' + - ' ' +
- '
' + - '
' +- ' ' +
- '
' + - ' ' +
- ' ' +
- '
' +
- '
调用方法:
- var dia = new MyDialog({
- title : title,
- bodyId : id,
- id : id + '_box'
- });
- dia.show();
具体可能还需要一定函数回调,各位可以自己封装一番。
拖放
工作中也经常会出现拖放效果的一些需求:
代码如下:
- function dragFunc(dragDiv, dragBody, dropBody) {
- if (!dropBody[0]) {
- dropBody = $(document);
- }
- if (dragDiv[0] && dragBody[0]) {
- var dragAble = false;
- var x1 = 0;
- var y1 = 0;
- var l = 10;
- var t = 10;
- var init_position = '';
- var init_cursor = '';
- var tmp_body = null;
- dragDiv.mousedown(function (e) {
- var ss = this;
- init_position = dragBody.css("position");
- init_cursor = dragBody.css("init_cursor");
- dragBody.css("position", "absolute");
- dragDiv.css("cursor", "move");
- tmp_body = $('
本文名称:前端工作中碰到的一些东西
URL网址:http://www.mswzjz.com/qtweb/news14/164964.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联
猜你还喜欢下面的内容