设为首页 加入收藏

TOP

自定义jq插件,鼠标悬浮展示图片或者视频放大图,可自定义展示内容(二)
2019-09-17 17:16:49 】 浏览:44
Tags:定义 插件 鼠标 悬浮 展示 图片 或者 视频 放大 内容
hown || this.winW < 1200) return; // 页面窗口小于1200 或者正在显示弹框 return this.initTool(e); let itemW = this.toolDom.width(), itemH = this.toolDom.height(), curX, curY, $curBox = $(e.target).closest(this.opts.item); // 获取当前悬浮元素的一些位置信息,对弹框位置的定义 let box = $curBox.get(0).getBoundingClientRect(); if(box.right > this.winW / 2) { curX = box.left - itemW - this.opts.oftX } else { curX = box.right + this.opts.oftX } if(this.opts.oftYPosition === 'top') { if(box.top < itemH) { if(box.top < 0) { curY = 0 } else { curY = box.top } } else { curY = box.top - itemH } } else if(this.opts.oftYPosition === 'bottom') { if(this.winH - box.bottom > itemH) { curY = box.bottom } else { curY = this.winH - itemH } } else { if((box.top + $curBox.outerHeight() / 2) < itemH / 2) { if(box.top < 0) { curY = 0 } else { curY = box.top } } else { if((box.bottom - $curBox.outerHeight() / 2) > (this.winH - itemH / 2)) { curY = this.winH - itemH } else { curY = box.top + $curBox.outerHeight() / 2 - itemH / 2 } } } this.scrollH = $(win).scrollTop(); this.toolDom.css({ left: curX, top: curY }); this.toolT = curY; // 展示方式 if(this.opts.fade) { this.toolDom.fadeIn() } else { this.toolDom.show() } this.playVideo() this.isShown = true } changeScrollTop(e) { // 根据滚动高度修改弹框位置 let scrollT = $(e.target).scrollTop(), reScrollT = this.scrollH, itemT = this.toolT, newScrollT; if(this.opts.followScroll && this.isShown) { newScrollT = reScrollT - scrollT; this.toolDom.css({ top: itemT + newScrollT, }); } } playVideo() { // 视频播放 setTimeout(()=> { this.opts.conCallback && this.toolDom.find('video').get(0).play() }, 0) } } $.fn[PLUGINNAME] = function(options) { this.each(function() { if (!$.data(this, "plugin_" + PLUGINNAME)) { $.data(this, "plugin_" + PLUGINNAME, new Plugin(this, options)); } }); return this; }; })(jQuery, window);

上面则是全部插件方法定义了,公司项目网站www.macdown.com, 这个插件主要用在视频与素材板块,即v.macdown.com的整站与sc.macdown.com的图库分类, 如果有兴趣可以来网站看一下效果
有很多不足希望能够指出,学习进步,互相关注,谢谢~

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇ie浏览器报 promise 问题 下一篇系列之前端:从重复造轮子说起

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目