HTML2canvas 生成图片:(下面使用方式源码)
http://html2canvas.hertzen.com/
https://github.com/niklasvh/html2canvas
JSzip 依赖 下载图片文件包:(下载压缩包源码)
https://stuk.github.io/jszip/documentation/examples/download-zip-file.html
// LESS 渐变变化
._transition(){
transition: all .3s ease-in-out; -ms-transition: all .3s ease-in-out;
}
// LESS 图片渐变放大样式
img {
width: 100%; height: 158px; overflow:hidden; border-radius:5px 5px 0 0; ._transition();
&:hover {
transform: scale(1.1); -ms-transform: scale(1.1); ._transition();
}
}
// Function
// 手机端输入框有时弹不出来,需要添加事件绑定,让窗口变化时,输入区强行滚动到视图区
var keyboard = function(domEvent) {
// ISO手机处理
this.isReset = true; // 是否归位
this.focusinHandler = function() {
this.isReset = false; // 聚焦时键盘弹出,焦点在输入框之间切换时,会先触发上一个输入框的失焦事件,再触发下一个输入框的聚焦事件
};
this.focusoutHandler = function() {
this.isReset = true;
setTimeout(function() {
// 当焦点在弹出层的输入框之间切换时先不归位
if (this.isReset) {
window.scroll(0, 0); // 确定延时后没有聚焦下一元素,是由收起键盘引起的失焦,则强制让页面归位
}
}, 30);
};
// Android 手机处理
this.originHeight = document.documentElement.clientHeight || document.body.clientHeight;
this.resizeHandler = function() {
var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
// 当前获得焦点的元素
var activeElement = document.activeElement;
if (resizeHeight < this.originHeight) {
// 键盘弹起后逻辑
if (activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA")) {
setTimeout(function() {
// 让当前的元素滚动到浏览器窗口的可视区域内。
// activeElement.scrollIntoView({
// block: 'center'
// });
activeElement.scrollIntoViewIfNeeded;
}, 0)
}
} else {
// 键盘收起后逻辑
}
};
// 解绑事件
this.unmount = function() {
if (this.focusinHandler && this.focusoutHandler) {
domEvent.removeEventListener('focusin', this.focusinHandler);
domEvent.removeEventListener('focusout', this.focusoutHandler);
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
}
}
// 入口函数
this.init = function(){
// 系统判断
var ua = window.navigator.userAgent.toLocaleLowerCase();
var isIOS = /iphone|ipad|ipod/.test(ua);
var isAndroid = /android/.test(ua);
if (isIOS) {
// console.info('isIOS')
// 上面 IOS 处理
domEvent.addEventListener('focus', this.focusinHandler);
domEvent.addEventListener('blur', this.focusoutHandler);
}
if (isAndroid) {
// 上面 Android 处理
// console.info('isAndroid')
window.addEventListener('resize', this.resizeHandler);
}
}
return this;
};
// Function Call
// 发送消息后,窗口自适应调整
if($('.inputArea').length){
keyboard($('.inputArea').get(0)).init();
}
var keyboard = function(domEvent) {
// ISO手机处理
this.isReset = true; // 是否归位
this.focusinHandler = function() {
this.isReset = false; // 聚焦时键盘弹出,焦点在输入框之间切换时,会先触发上一个输入框的失焦事件,再触发下一个输入框的聚焦事件
};
this.focusoutHandler = function() {
this.isReset = true;
setTimeout(function() {
// 当焦点在弹出层的输入框之间切换时先不归位
if (this.isReset) {
window.scroll(0, 0); // 确定延时后没有聚焦下一元素,是由收起键盘引起的失焦,则强制让页面归位
}
}, 30);
};
// Android 手机处理
this.originHeight = document.documentElement.clientHeight || document.body.clientHeight;
this.resizeHandler = function() {
var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
// 当前获得焦点的元素
var activeElement = document.activeElement;
if (resizeHeight < this.originHeight) {
// 键盘弹起后逻辑
if (activeElement && (activeElement.tagName === "INPUT" || activeElement.tagName === "TEXTAREA")) {
setTimeout(function() {
// 让当前的元素滚动到浏览器窗口的可视区域内。
activeElement.scrollIntoView({
block: 'center'
});
}, 0)
}
} else {
// 键盘收起后逻辑
}
};
// 解绑事件
this.unmount = function() {
if (this.focusinHandler && this.focusoutHandler) {
domEvent.removeEventListener('focusin', this.focusinHandler);
domEvent.removeEventListener('focusout', this.focusoutHandler);
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
}
}
// 入口函数
this.init = function(){
// 系统判断
var ua = window.navigator.userAgent.toLocaleLowerCase();
var isIOS = /iphone|ipad|ipod/.test(ua);
var isAndroid = /android/.test(ua);
if (isIOS) {
// 上面 IOS 处理
domEvent.addEventListener('focus', this.focusinHandler);
domEvent.addEventListener('blur', this.focusoutHandler);
}
if (isAndroid) {
// 上面 Android 处理
window.addEventListener('resize', this.resizeHandler);
}
}
};
HTML
<div class="more up"><em>展开</em><u><i></i></u></div>
CSS
.more {
.font(b,14px,32px); float: right; cursor: pointer;
em { float: left; color: #333; margin-right:8px; font-weight:normal; }
u {
position: relative; display: block; width: 0; height: 0; float: left;
margin-top: 14px;
border-right: 6px solid transparent;
border-top: 7px solid #666;
border-left: 6px solid transparent;
}
i {
position: absolute; display: block; left: -6px; bottom: 2px; width: 0; height: 0;
border-right: 6px solid transparent;
border-top: 7px solid #fff;
border-left: 6px solid transparent;
}
&:hover {
em { color: #189AE5; }
u { border-top: 7px solid #189AE5; }
}
// 向上
&.up {
u {
border-bottom: 7px solid #666;
border-top: none;
}
i {
top: 2px; bottom: auto;
border-bottom: 7px solid #fff;
border-top: none;
}
&:hover {
em { color: #189AE5; }
u { border-bottom: 7px solid #189AE5; }
}
}
}
// 倒计时函数
countdown = function(timeStamp, secondFn, finishFn) {
if (typeof timeStamp == 'undefined' || typeof timeStamp != 'number') return;
var _secondFn = secondFn || function() {},
_finishFn = finishFn || function() {},
_timer,
_timeStamp = timeStamp,
_day,
_hour,
_minute,
_second;
function count() {
_timeStamp = _timeStamp - 1;
if (_timeStamp <= 0) {
clearInterval(_timer);
_day = _hour = _minute = _second = '00';
_secondFn(_day, _hour, _minute, _second);
_finishFn();
}
_day = Math.floor(_timeStamp / ( 3600 * 24 ));
_hour = Math.floor((_timeStamp % ( 3600 * 24 )) / 3600);
_minute = Math.floor((_timeStamp % 3600) / 60);
_second = parseInt(_timeStamp) % 60;
//补0
_day = (_day < 10 ? '0' + _day : _day + '');
_hour = (_hour < 10 ? '0' + _hour : _hour + '');
_minute = (_minute < 10 ? '0' + _minute : _minute + '');
_second = (_second < 10 ? '0' + _second : _second + '');
_secondFn(_day, _hour, _minute, _second);
}
_timer = setInterval(count, 1000);
};
/**
*
* @authors Your Name (you@example.org)
* @date 2020-02-20 13:02:44
* @version $Id$
*/
// 谭子良 右侧固定代码优化
// id 右侧固定容器
// offsetBotton 底部固定位置
function aFixedbottom(id, offsetBotton) {
var offsetBotton = offsetBotton || 0;
var objMarginLeft = 0;
var isIE6 = ($.browser.msie && $.browser.version == '6.0') ? true : false;
var Container = $('#' + id);
if (Container.length != 1) return 'fixedbottom不能正确获取id';
var initTop = Container.offset().top,
initHeight = Container.height(),
initWidth = Container.width(),
initOutWidth = Container.outerWidth(),
initWinH = $(window).height(),
initBodyH = $('body').height();
var Shadow = $('<div id="js_fixedbot_shadow"></div>').addClass(Container.attr('class')).height(initHeight).css({
'visibility': 'hidden',
'display': 'none'
});
Container.after(Shadow);
//页面高度、侧边栏高度均达不到一屏高度的情况下,无需脚本处理
//if( initBodyH<=initWinH || initHeight<=initWinH ) return null;
var fixedFlag = false;
var triggerHeight;
objMarginLeft = 1000 - initOutWidth - 500;
this.setObjMarginLeft = function(wrapperWidth) {
wrapperWidth = wrapperWidth ? wrapperWidth : 1000;
objMarginLeft = wrapperWidth - initOutWidth - wrapperWidth / 2;
}
this.init = function() {
var that = this;
setInterval(function() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var winH = $(window).height();
//临界值(触发高度)
if (!fixedFlag) {
triggerHeight = Container.height() + Container.offset().top - $(window).height() + offsetBotton;
}
if (scrollTop >= triggerHeight) {
fixedFlag = true;
if (!isIE6) {
Container.css({
'position': 'fixed',
'width': initWidth,
'top': 'auto',
'bottom': offsetBotton,
'left': '50%',
'marginLeft': objMarginLeft
});
Shadow.css('display', 'block');
}
} else {
fixedFlag = false;
if (!isIE6) {
Container.css({
'position': 'static',
'marginLeft': 0
})
Shadow.css('display', 'none');
}
}
}, 40);
}
};
// 右侧栏固定效果
if ($('#adFix').length > 0) {
var Fixedbottom = new aFixedbottom('adFix',94);
Fixedbottom.init();
}
// --------------------------------------
// 谭子良 右侧固定代码优化
// id 右侧固定容器
// offsetBotton 底部固定位置
// endOffsetBotton 滚动条至页面底部时的最终 底部固定位置
function aFixedbottom(id, offsetBotton,endOffsetBotton) {
var offsetBotton = offsetBotton || 0;
var objMarginLeft = 0;
var isIE6 = ($.browser.msie && $.browser.version == '6.0') ? true : false;
var Container = $('#' + id);
if (Container.length != 1) return 'fixedbottom不能正确获取id';
var initTop = Container.offset().top,
initHeight = Container.height(),
initWidth = Container.width(),
initOutWidth = Container.outerWidth(),
initWinH = $(window).height(),
initBodyH = $('body').height();
var Shadow = $('<div id="js_fixedbot_shadow"></div>').addClass(Container.attr('class')).height(initHeight).css({
'visibility': 'hidden',
'display': 'none'
});
Container.after(Shadow);
//页面高度、侧边栏高度均达不到一屏高度的情况下,无需脚本处理
//if( initBodyH<=initWinH || initHeight<=initWinH ) return null;
var fixedFlag = false;
var triggerHeight;
objMarginLeft = 1000 - initOutWidth - 500;
this.setObjMarginLeft = function(wrapperWidth) {
wrapperWidth = wrapperWidth ? wrapperWidth : 1000;
objMarginLeft = wrapperWidth - initOutWidth - wrapperWidth / 2;
}
this.init = function() {
var that = this;
setInterval(function() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var winH = $(window).height();
//183为footer的高度
var contentHeight = $('body').height() - endOffsetBotton;
//临界值(触发高度)
if (!fixedFlag) {
triggerHeight = Container.height() + Container.offset().top - $(window).height() + offsetBotton;
}
if (scrollTop >= triggerHeight) {
fixedFlag = true;
if (!isIE6) {
if (scrollTop >= (contentHeight - winH + offsetBotton)) {
Container.css({
'position': 'absolute',
'width': initWidth,
'bottom': 'auto',
'top': contentHeight - Container.height(),
'left': '50%',
'marginLeft': objMarginLeft
});
} else {
Container.css({
'position': 'fixed',
'width': initWidth,
'top': 'auto',
'bottom': offsetBotton,
'left': '50%',
'marginLeft': objMarginLeft
});
}
Shadow.css('display', 'block');
}
} else {
fixedFlag = false;
if (!isIE6) {
Container.css({
'position': 'static',
'marginLeft': 0
})
Shadow.css('display', 'none');
}
}
}, 40);
}
};
// 右侧栏固定效果
if ($('#adFix').length > 0) {
var Fixedbottom = new aFixedbottom('adFix',10,94);
Fixedbottom.init();
}
IOS 手机浏览屏底部被挡住的CSS解决代码片断
padding-top: env(safe-area-inset-top);
padding-bottom: env(safe-area-inset-bottom);
/**
* 得到目录下所有文件数组(仅是文件名)
*/
function foreachDir($path){
$fileArray = array();
// 打开文件夹
if( $handle=opendir($path) ){
while ( false !== ($file = readdir($handle)) ) {
// 排除 当前目录 上级目录
if( $file!="." && $file!='..'){
// 打开的是目录
if(is_dir($path.$file)){
foreachDir($path.$file);
// 打开的是文件
}else{
$fileArray[] = $file;
}
}
}
return $fileArray;
}
}
// 得到目录下所有文件数组(仅是文件名)
$fileList = foreachDir('./textbooks');