foldcontent-zhihu
Advanced tools
Comparing version 3.0.5 to 3.0.6
;(function ($, window, document, undefined) { | ||
//定义 FoldContent 的构造函数 | ||
var FoldContent = function (ele,opt) { | ||
var foldcontent_jquery = function (ele,opt) { | ||
this.$element = ele; | ||
@@ -17,3 +17,3 @@ this.defaults = { | ||
//定义方法 | ||
FoldContent.prototype = { | ||
foldcontent_jquery.prototype = { | ||
config: function () { | ||
@@ -98,6 +98,6 @@ this.$element.css({ | ||
//创建 FoldContent 的实体 | ||
var foldContent = new FoldContent(this, options); | ||
var foldcontent_j = new foldcontent_jquery(this, options); | ||
//调用其方法 | ||
foldContent.config(); | ||
foldContent.fontContentFunction(); | ||
foldcontent_j.config(); | ||
foldcontent_j.fontContentFunction(); | ||
} | ||
@@ -104,0 +104,0 @@ })(jQuery, window, document); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("foldcontent",[],e):"object"==typeof exports?exports.foldcontent=e():t.foldcontent=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return t[o].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r,i,s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}();n(1),function(){var l=function(){function t(e){o(this,t);var n={btnBg:"#eff6fa",btnColor:"#0c5897",fixBtnBg:"#81baeb",fixBtnColor:"#fff",fontSize:"12px",padding:"5px",initialText:"展开",fixText:"收起",bottom:"10px",right:"20px",lineHeight:"1"};for(var r in n)n.hasOwnProperty(r)&&!e.hasOwnProperty(r)&&(e[r]=n)}return a(t,[{key:"init",value:function(t){var e=Number($(".unfold").css("padding").replace("px","")),n=Number($(".unfold").css("font-size").replace("px","")),o=Number($(".foldcontent-panel").css("width").replace("px","")),r=Number($(".foldcontent-panel").css("padding-Bottom").replace("px","")),i=Number(t.right.replace("px","")),a=t.initialText,l=t.fixText;console.log(s($(".unfold").css("padding")));var f=r+2*e+n,c=$(document),u=$(window);c.on("click",".unfold",function(){var e=$(this);if(e.text()!==l){e.text(l).siblings(".part-content").hide().siblings(".all-content").show();var n=e.parent(),r=n.offset().top+n.height(),s=c.scrollTop()+u.height(),p=(u.width()-o)/2+i>i?(u.width()-o)/2+i:i;s-r<f&&(e.css({right:p}),this.changeToFix(e,t));var d={onscroll:function(){var r=n.offset().top+n.height(),s=c.scrollTop()+u.height(),l=(u.width()-o)/2+i>i?(u.width()-o)/2+i:i;s-r<f&&n.offset().top-s<-90&&e.text()!==a?(e.css({right:l}),this.changeToFix(e,t)):this.changeStyle(e,t),u.off("scroll",d.onscroll),setTimeout(function(){u.on("scroll",d.onscroll)},50)}};u.on("scroll",d.onscroll)}else{var h=$(this);changeStyle(h),h.text(a).siblings(".part-content").show().siblings(".all-content").hide()}})}},{key:"changeStyle",value:function(t,e){t.css({right:"20px",color:e.btnColor,backgroundColor:e.btnBg,position:"absolute"})}},{key:"changeToFix",value:function(t,e){t.css({color:e.fixBtnColor,backgroundColor:e.fixBtnBg,position:"fixed"})}}]),t}();r=l,i="function"==typeof r?r.call(e,n,e,t):r,!(void 0!==i&&(t.exports=i))}()},function(t,e,n){var o=n(2);"string"==typeof o&&(o=[[t.id,o,""]]);n(4)(o,{});o.locals&&(t.exports=o.locals)},function(t,e,n){e=t.exports=n(3)(),e.push([t.id,".foldcontent-panel{box-sizing:border-box;position:relative;width:700px;margin:20px auto;padding:30px;color:#666;line-height:2.5;border:1px solid #eee;box-shadow:5px 6px 5px #ccc}.all-content{display:none}",""])},function(t,e){t.exports=function(){var t=[];return t.toString=function(){for(var t=[],e=0;e<this.length;e++){var n=this[e];n[2]?t.push("@media "+n[2]+"{"+n[1]+"}"):t.push(n[1])}return t.join("")},t.i=function(e,n){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},r=0;r<this.length;r++){var i=this[r][0];"number"==typeof i&&(o[i]=!0)}for(r=0;r<e.length;r++){var s=e[r];"number"==typeof s[0]&&o[s[0]]||(n&&!s[2]?s[2]=n:n&&(s[2]="("+s[2]+") and ("+n+")"),t.push(s))}},t}},function(t,e,n){function o(t,e){for(var n=0;n<t.length;n++){var o=t[n],r=d[o.id];if(r){r.refs++;for(var i=0;i<r.parts.length;i++)r.parts[i](o.parts[i]);for(;i<o.parts.length;i++)r.parts.push(f(o.parts[i],e))}else{for(var s=[],i=0;i<o.parts.length;i++)s.push(f(o.parts[i],e));d[o.id]={id:o.id,refs:1,parts:s}}}}function r(t){for(var e=[],n={},o=0;o<t.length;o++){var r=t[o],i=r[0],s=r[1],a=r[2],l=r[3],f={css:s,media:a,sourceMap:l};n[i]?n[i].parts.push(f):e.push(n[i]={id:i,parts:[f]})}return e}function i(t,e){var n=g(),o=y[y.length-1];if("top"===t.insertAt)o?o.nextSibling?n.insertBefore(e,o.nextSibling):n.appendChild(e):n.insertBefore(e,n.firstChild),y.push(e);else{if("bottom"!==t.insertAt)throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");n.appendChild(e)}}function s(t){t.parentNode.removeChild(t);var e=y.indexOf(t);e>=0&&y.splice(e,1)}function a(t){var e=document.createElement("style");return e.type="text/css",i(t,e),e}function l(t){var e=document.createElement("link");return e.rel="stylesheet",i(t,e),e}function f(t,e){var n,o,r;if(e.singleton){var i=x++;n=b||(b=a(e)),o=c.bind(null,n,i,!1),r=c.bind(null,n,i,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=l(e),o=p.bind(null,n),r=function(){s(n),n.href&&URL.revokeObjectURL(n.href)}):(n=a(e),o=u.bind(null,n),r=function(){s(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else r()}}function c(t,e,n,o){var r=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=m(e,r);else{var i=document.createTextNode(r),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(i,s[e]):t.appendChild(i)}}function u(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function p(t,e){var n=e.css,o=e.sourceMap;o&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var r=new Blob([n],{type:"text/css"}),i=t.href;t.href=URL.createObjectURL(r),i&&URL.revokeObjectURL(i)}var d={},h=function(t){var e;return function(){return"undefined"==typeof e&&(e=t.apply(this,arguments)),e}},v=h(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),g=h(function(){return document.head||document.getElementsByTagName("head")[0]}),b=null,x=0,y=[];t.exports=function(t,e){e=e||{},"undefined"==typeof e.singleton&&(e.singleton=v()),"undefined"==typeof e.insertAt&&(e.insertAt="bottom");var n=r(t);return o(n,e),function(t){for(var i=[],s=0;s<n.length;s++){var a=n[s],l=d[a.id];l.refs--,i.push(l)}if(t){var f=r(t);o(f,e)}for(var s=0;s<i.length;s++){var l=i[s];if(0===l.refs){for(var c=0;c<l.parts.length;c++)l.parts[c]();delete d[l.id]}}}};var m=function(){var t=[];return function(e,n){return t[e]=n,t.filter(Boolean).join("\n")}}()}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("foldcontent",[],t):"object"==typeof exports?exports.foldcontent=t():e.foldcontent=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var r=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}();n(1),function(){var t=function(){function e(t){o(this,e);var n={container:document.getElementsByClassName("foldcontent-panel"),btnBg:"#eff6fa",btnColor:"#0c5897",fixBtnBg:"#81baeb",fixBtnColor:"#fff",fontSize:"12px",padding:"5px",initialText:"展开",fixText:"收起",bottom:"10px",right:"20px",lineHeight:"1"};for(var r in n)n.hasOwnProperty(r)&&!t.hasOwnProperty(r)&&(t[r]=n[r]);this.container=t.container,this.init(t)}return r(e,[{key:"init",value:function(e){var t=this,n=document,o=window,r=n.getElementsByClassName("unfold"),i=parseInt(e.right),a=e.initialText,l=e.fixText,s='<div class="unfold" style="background-color: '+e.btnBg+"; color: "+e.btnColor+"; font-size: "+(parseInt(e.fontSize)+"px")+";\n line-height: "+e.lineHeight+"; right: "+e.right+";bottom: "+e.bottom+"; padding: "+e.padding+';">'+e.initialText+"</div>";Array.from(this.container).forEach(function(e){e.innerHTML+=s});for(var f=function(s){r[s].addEventListener("click",function(r){var f=r.target,c=n.getElementsByClassName("part-content")[s],u=n.getElementsByClassName("all-content")[s],d=parseInt(f.style.padding);f.innerHTML!==l?!function(){f.innerHTML=l,t.toggle(c,u);var r=f.parentNode,s=parseInt(window.getComputedStyle(r,null).getPropertyValue("width")),p=o.innerHeight||n.documentElement.clientHeight||n.body.clientHeight||0,h=n.documentElement.getBoundingClientRect().width||0,g=o.pageYOffset||n.body.scrollTop||n.documentElement.scrollTop||0;p+=g;for(var v=r.offsetTop,y=r.offsetParent;null!==y;)v+=y.offsetTop,y=y.offsetParent;v+=r.clientHeight;var m=(h-s)/2+i>i?(h-s)/2+i:i;p-v<d&&(f.style.right=m+"px",t.changeFix(f,e));var b={onscroll:function(){var l=o.innerHeight||n.documentElement.clientHeight||n.body.clientHeight||0,c=n.documentElement.getBoundingClientRect().width||0,u=o.pageYOffset||n.body.scrollTop||n.documentElement.scrollTop||0;l+=u;for(var p=r.offsetTop,h=r.offsetParent;null!==h;)p+=h.offsetTop,h=h.offsetParent;var g=p+r.clientHeight,v=(c-s)/2+i>i?(c-s)/2+i:i;l-g<d&&l-p>90&&f.innerHTML!==a?(f.style.right=v+"px",t.changeFix(f,e)):t.changeStyle(f,e),n.removeEventListener("scroll",b.onscroll,!1),setTimeout(function(){n.addEventListener("scroll",b.onscroll)},50)}};n.addEventListener("scroll",b.onscroll,!1)}():(t.changeStyle(f,e),f.innerHTML=a,t.toggle(c,u))})},c=0;c<r.length;c++)f(c)}},{key:"toggle",value:function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];var o=!0,r=!1,i=void 0;try{for(var a,l=t[Symbol.iterator]();!(o=(a=l.next()).done);o=!0){var s=a.value;"none"!==s.style.display?s.style.display="none":s.style.display="block"}}catch(e){r=!0,i=e}finally{try{!o&&l.return&&l.return()}finally{if(r)throw i}}}},{key:"changeStyle",value:function(e,t){var n=e.style;n.right=t.right,n.color=t.btnColor,n.backgroundColor=t.btnBg,n.position="absolute"}},{key:"changeFix",value:function(e,t){var n=e.style;n.color=t.fixBtnColor,n.backgroundColor=t.fixBtnBg,n.position="fixed"}}]),e}();"undefined"!=typeof e&&"undefined"!=typeof e.exports?e.exports=t:window.foldContent=t}()},function(e,t,n){var o=n(2);"string"==typeof o&&(o=[[e.id,o,""]]);n(4)(o,{});o.locals&&(e.exports=o.locals)},function(e,t,n){t=e.exports=n(3)(),t.push([e.id,".foldcontent-panel{box-sizing:border-box;position:relative;width:700px;margin:20px auto;padding:30px;color:#666;line-height:2.5;border:1px solid #eee;box-shadow:5px 6px 5px #ccc}.all-content{display:none}.unfold{position:absolute;border-radius:5px}",""])},function(e,t){e.exports=function(){var e=[];return e.toString=function(){for(var e=[],t=0;t<this.length;t++){var n=this[t];n[2]?e.push("@media "+n[2]+"{"+n[1]+"}"):e.push(n[1])}return e.join("")},e.i=function(t,n){"string"==typeof t&&(t=[[null,t,""]]);for(var o={},r=0;r<this.length;r++){var i=this[r][0];"number"==typeof i&&(o[i]=!0)}for(r=0;r<t.length;r++){var a=t[r];"number"==typeof a[0]&&o[a[0]]||(n&&!a[2]?a[2]=n:n&&(a[2]="("+a[2]+") and ("+n+")"),e.push(a))}},e}},function(e,t,n){function o(e,t){for(var n=0;n<e.length;n++){var o=e[n],r=p[o.id];if(r){r.refs++;for(var i=0;i<r.parts.length;i++)r.parts[i](o.parts[i]);for(;i<o.parts.length;i++)r.parts.push(f(o.parts[i],t))}else{for(var a=[],i=0;i<o.parts.length;i++)a.push(f(o.parts[i],t));p[o.id]={id:o.id,refs:1,parts:a}}}}function r(e){for(var t=[],n={},o=0;o<e.length;o++){var r=e[o],i=r[0],a=r[1],l=r[2],s=r[3],f={css:a,media:l,sourceMap:s};n[i]?n[i].parts.push(f):t.push(n[i]={id:i,parts:[f]})}return t}function i(e,t){var n=v(),o=b[b.length-1];if("top"===e.insertAt)o?o.nextSibling?n.insertBefore(t,o.nextSibling):n.appendChild(t):n.insertBefore(t,n.firstChild),b.push(t);else{if("bottom"!==e.insertAt)throw new Error("Invalid value for parameter 'insertAt'. Must be 'top' or 'bottom'.");n.appendChild(t)}}function a(e){e.parentNode.removeChild(e);var t=b.indexOf(e);t>=0&&b.splice(t,1)}function l(e){var t=document.createElement("style");return t.type="text/css",i(e,t),t}function s(e){var t=document.createElement("link");return t.rel="stylesheet",i(e,t),t}function f(e,t){var n,o,r;if(t.singleton){var i=m++;n=y||(y=l(t)),o=c.bind(null,n,i,!1),r=c.bind(null,n,i,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=s(t),o=d.bind(null,n),r=function(){a(n),n.href&&URL.revokeObjectURL(n.href)}):(n=l(t),o=u.bind(null,n),r=function(){a(n)});return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else r()}}function c(e,t,n,o){var r=n?"":o.css;if(e.styleSheet)e.styleSheet.cssText=x(t,r);else{var i=document.createTextNode(r),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function u(e,t){var n=t.css,o=t.media;if(o&&e.setAttribute("media",o),e.styleSheet)e.styleSheet.cssText=n;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(n))}}function d(e,t){var n=t.css,o=t.sourceMap;o&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var r=new Blob([n],{type:"text/css"}),i=e.href;e.href=URL.createObjectURL(r),i&&URL.revokeObjectURL(i)}var p={},h=function(e){var t;return function(){return"undefined"==typeof t&&(t=e.apply(this,arguments)),t}},g=h(function(){return/msie [6-9]\b/.test(window.navigator.userAgent.toLowerCase())}),v=h(function(){return document.head||document.getElementsByTagName("head")[0]}),y=null,m=0,b=[];e.exports=function(e,t){t=t||{},"undefined"==typeof t.singleton&&(t.singleton=g()),"undefined"==typeof t.insertAt&&(t.insertAt="bottom");var n=r(e);return o(n,t),function(e){for(var i=[],a=0;a<n.length;a++){var l=n[a],s=p[l.id];s.refs--,i.push(s)}if(e){var f=r(e);o(f,t)}for(var a=0;a<i.length;a++){var s=i[a];if(0===s.refs){for(var c=0;c<s.parts.length;c++)s.parts[c]();delete p[s.id]}}}};var x=function(){var e=[];return function(t,n){return e[t]=n,e.filter(Boolean).join("\n")}}()}])}); | ||
//# sourceMappingURL=foldcontent.min.js.map |
;(function (window, document, undefined) { | ||
//定义 FoldContent 的构造函数 | ||
var FoldContent = function (ele,opt) { | ||
//定义 foldcontent_jquery 的构造函数 | ||
var foldcontent_jquery = function (ele,opt) { | ||
this.$element = ele; | ||
@@ -21,3 +21,3 @@ this.defaults = { | ||
//定义方法 | ||
FoldContent.prototype = { | ||
foldcontent_jquery.prototype = { | ||
config: function () { | ||
@@ -43,10 +43,10 @@ this.$element.text(this.options.initialText); | ||
btnBg = this.options.btnBg, | ||
btnPadding = Number($('.unfold').css('padding').replace('px', '')), | ||
btnFontSize = Number($('.unfold').css('font-size').replace('px', '')), | ||
panelWidth = Number($('.foldcontent-panel').css('width').replace('px','')), | ||
panelPaddingBtm = Number($('.foldcontent-panel').css('padding-Bottom').replace('px', '')), | ||
btnRight = Number((this.options.right).replace('px', '')), | ||
btnPadding = parseInt($('.unfold').css('padding')) || 0, | ||
btnFontSize = parseInt($('.unfold').css('font-size')) || 0, | ||
panelWidth = parseInt($('.foldcontent-panel').css('width')) || 0, | ||
panelPaddingBtm = parseInt($('.foldcontent-panel').css('padding-Bottom')) || 0, | ||
btnRight = parseInt((this.options.right)), | ||
initialText = this.options.initialText, | ||
fixText = this.options.fixText; | ||
var btnBottom = panelPaddingBtm + btnPadding * 2 + btnFontSize; | ||
var btnBottom = panelPaddingBtm + btnPadding * 2 + btnFontSize + parseInt(this.options.bottom) || 0; | ||
var doc = $(document); | ||
@@ -117,10 +117,10 @@ var win = $(window); | ||
}; | ||
//在插件中使用 FoldContent 对象 | ||
//在插件中使用 foldcontent_jquery 对象 | ||
$.fn.foldContentPlugin = function (options) { | ||
//创建 FoldContent 的实体 | ||
var foldContent = new FoldContent(this, options); | ||
var foldcontent_j = new foldcontent_jquery(this, options); | ||
//调用其方法 | ||
foldContent.config(); | ||
foldContent.fontContentFunction(); | ||
foldcontent_j.config(); | ||
foldcontent_j.fontContentFunction(); | ||
} | ||
})(window, document); |
{ | ||
"name": "foldcontent-zhihu", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"description": "用原生 js && jquery 实现知乎收起答案功能", | ||
@@ -5,0 +5,0 @@ "main": "dist/foldcontent.min.js", |
@@ -10,4 +10,11 @@ # foldcontent-zhihu | ||
src/ 目录下是原生 js 写法🌰 | ||
jquery/ 目录下是 jquery 写法🌰 | ||
main: | ||
dist/foldcontent.min.js | ||
dist/foldcontent_jquery.min.js | ||
## Install | ||
@@ -18,3 +25,3 @@ | ||
``` | ||
$ npm install foldcontent-zhihu@">=3.0.5" --save | ||
$ npm install foldcontent-zhihu@">=3.0.6" --save | ||
``` | ||
@@ -27,3 +34,3 @@ | ||
#### Work with module bundler | ||
#### 方法一: Work with module bundler | ||
@@ -42,3 +49,3 @@ ##### HTML | ||
```JS | ||
var foldcontent = require('foldcontent'); | ||
var foldcontent = require('foldcontent-zhihu'); | ||
var foldcontent_demo = new foldcontent({ | ||
@@ -59,3 +66,3 @@ 'btnBg': '#eff6fa', | ||
#### 直接通过 script 标签引入 dist/目录下的 foldcontent.min.js 文件 | ||
#### 方法二: 直接通过 script 标签引入 dist/目录下的 foldcontent.min.js 文件 | ||
@@ -83,4 +90,5 @@ ##### HTML | ||
#### 方法一: script 标签引入 dist/目录下的 foldcontent_jquery.min.js 文件 | ||
#### HTML | ||
##### HTML | ||
@@ -94,7 +102,6 @@ ```HTML | ||
<script src="../demo/js/01-jquery-1.11.3.min.js"></script> | ||
<script src="foldcontent.min.js"></script> | ||
<script src="foldcontent_jquery.min.js"></script> | ||
``` | ||
#### JS | ||
##### 方法一: script 标签引入 jquery/目录下的 foldcontent.jquery.js 文件 | ||
##### JS | ||
@@ -109,4 +116,29 @@ ```JS | ||
##### 方法二: webpack 加载 | ||
#### 方法二: webpack 加载 | ||
##### HTML | ||
```HTML | ||
<div class="foldcontent-panel"> | ||
<div class="part-content"><!--此处是部分内容--></div> | ||
<div class="all-content"><!--此处是全部内容--></div> | ||
</div> | ||
<!-- ... --> | ||
<script src="../demo/js/01-jquery-1.11.3.min.js"></script> | ||
<script src="foldcontent_jquery.min.js"></script> | ||
``` | ||
##### js | ||
``` | ||
require('foldcontent-zhihu'); | ||
$(function () { | ||
$('.unfold').foldContentPlugin({ | ||
// ... | ||
}); | ||
}); | ||
``` | ||
###### webpack | ||
``` | ||
// webpack 全局加载 jquery 的一种方法 | ||
@@ -113,0 +145,0 @@ resolve: { |
@@ -50,9 +50,9 @@ require('./style.css'); | ||
target.innerHTML = fixText; | ||
this.toggle(part); | ||
this.toggle(all); | ||
this.toggle(part, all); | ||
let panel = target.parentNode, | ||
panelWidth = parseInt(window.getComputedStyle(panel,null).getPropertyValue('width')), | ||
h = win.innerHeight || doc.documentElement.clientHeight || doc.body.clientHeight || 0, | ||
w = win.innerWidth || doc.documentElement.clientWidth || doc.body.clientWidth || 0, | ||
s = win.pageXOffset || doc.body.scrollTop || doc.documentElement.scrollTop || 0; | ||
w = doc.documentElement.getBoundingClientRect().width || 0, | ||
// jquery width() 方法, 不包含滚动条宽度 vs document.body.clientWidth == document.body.offsetWidth window.innerWidth) | ||
s = win.pageYOffset || doc.body.scrollTop || doc.documentElement.scrollTop || 0; | ||
h = h + s; | ||
@@ -65,3 +65,3 @@ let t = panel.offsetTop, | ||
} | ||
t += panel.offsetHeight; | ||
t += panel.clientHeight; | ||
let right = (w - panelWidth) / 2 + btnRight > btnRight ? | ||
@@ -76,4 +76,4 @@ (w - panelWidth) / 2 + btnRight : btnRight; | ||
let h = win.innerHeight || doc.documentElement.clientHeight || doc.body.clientHeight || 0, | ||
w = win.innerWidth || doc.documentElement.clientWidth || doc.body.clientWidth || 0, | ||
s = win.pageXOffset || doc.body.scrollTop || doc.documentElement.scrollTop || 0; | ||
w = doc.documentElement.getBoundingClientRect().width || 0, | ||
s = win.pageYOffset || doc.body.scrollTop || doc.documentElement.scrollTop || 0; | ||
h = h + s; | ||
@@ -86,6 +86,6 @@ let t = panel.offsetTop, | ||
} | ||
let th = t + panel.offsetHeight, | ||
let th = t + panel.clientHeight, | ||
right = (w - panelWidth) / 2 + btnRight > btnRight ? | ||
(w - panelWidth) / 2 + btnRight : btnRight; | ||
if (th - h > btnBottom && h - t > 90 && target.innerHTML !== initialText) { | ||
if (h - th < btnBottom && h - t > 90 && target.innerHTML !== initialText) { | ||
target.style.right = right + 'px'; | ||
@@ -96,14 +96,13 @@ this.changeFix(target, option); | ||
} | ||
win.removeEventListener("scroll", cb.onscroll, false); | ||
doc.removeEventListener("scroll", cb.onscroll, false); | ||
setTimeout(() => { | ||
win.addEventListener("scroll", cb.onscroll); | ||
doc.addEventListener("scroll", cb.onscroll); | ||
}, 50); | ||
} | ||
}; | ||
win.addEventListener('scroll', cb.onscroll, false); | ||
doc.addEventListener('scroll', cb.onscroll, false); | ||
} else { | ||
this.changeStyle(target, option); | ||
target.innerHTML = initialText; | ||
this.toggle(part); | ||
this.toggle(all); | ||
this.toggle(part, all); | ||
} | ||
@@ -113,7 +112,10 @@ }); | ||
} | ||
toggle(i) { | ||
if (i.style.display !== 'none') { | ||
i.style.display = 'none' | ||
} else { | ||
i.style.display = 'block' | ||
// ES6 布丁参数, 停止使用 arguments | ||
toggle(...list) { | ||
for(let i of list) { | ||
if (i.style.display !== 'none') { | ||
i.style.display = 'none' | ||
} else { | ||
i.style.display = 'block' | ||
} | ||
} | ||
@@ -120,0 +122,0 @@ } |
@@ -11,6 +11,8 @@ var webpack = require('webpack'); | ||
devtool: 'source-map', | ||
entry: './src/foldcontent.jquery.js', | ||
entry: { | ||
foldcontent: './src/foldcontent.js', | ||
foldcontent_jquery: './jquery/foldcontent.jquery.js'}, | ||
output: { | ||
path: BUILD_PATH, | ||
filename: 'foldcontent.min.js', | ||
filename: '[name].min.js', | ||
library: 'foldcontent', | ||
@@ -24,2 +26,3 @@ libraryTarget: 'umd', | ||
publicPath: "/dist/", | ||
port: 8081 | ||
}, | ||
@@ -26,0 +29,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
237928
22
1039
178