console.log('http://www.ishutime.com 鉂わ笍鉂わ笍鉂わ笍 鎷捐叮鍝佺墝');
(function (global, factory) {
(global.util = factory());
}(this, (function () {
// 'use strict'; ie9涓嶆敮鎸
if (!util) {
var util = {
/************************************************************************
* ui
************************************************************************/
/**
*瀵硅瘽鎻愮ず妗
*
* @param {*} [string=''] 鏄剧ず鐨勬枃妗
* @param {*} [type='normal'] '榛樿鍗婇€忔槑,success 缁胯壊,error 绾㈣壊, warning 榛勮壊'
*/
toast: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
string: '',
type: 'normal',
}, config);
}
var $toast = document.getElementsByClassName('_toast')[0]
util.addClass($toast, 'active')
util.removeClass($toast, 'success')
$toast.childNodes[0].childNodes[0].innerHTML = config.string
switch (config.type) {
case 'normal':
break;
case 'success':
util.addClass($toast, 'success')
break;
case 'error':
util.addClass($toast, 'error')
break;
case 'warning':
util.addClass($toast, 'warning')
break;
default:
break;
}
setTimeout(function () {
$toast.className = '_toast'
}, 1500)
},
/**
* 鍏夋爣
* @param {*} $cursor //鍏夋爣
* @param {*} $must //鍏夋爣鑼冨洿
*/
cursor: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
$cursor: '',
$must: '',
}, config);
}
var position = {
x: 0,
y: 0
},
show = false,
dragg = false;
ani()
function ani(param) {
requestAnimationFrame(ani)
render()
}
function render() {
if (show) {
/** @type {HTMLElement} */
config.$cursor.classList.add('show-pointer')
TweenMax.to(config.$cursor, .15, {
left: position.x + 'px',
top: position.y + 'px'
})
} else {
config.$cursor.classList.remove('show-pointer')
}
}
config.$must.addEventListener('mousemove', function (e) {
position.x = e.clientX
position.y = e.clientY
}, false)
config.$must.addEventListener('mousedown', function (e) {
console.log('?')
util.addClass(config.$cursor, 'active')
}, false)
config.$must.addEventListener('mouseup', function (e) {
util.removeClass(config.$cursor, 'active')
}, false)
config.$must.addEventListener('mouseleave', function (e) {
show = false
// console.log('leave')
}, false)
config.$must.addEventListener('mouseenter', function (e) {
show = true
// console.log('in')
}, false)
},
/**
*鐐瑰嚮鐪嬪ぇ鍥
*
* @param {obj} $Album //鍒楄〃鐖剁骇
* @param {obj} startUp //榛樿鎵撳紑绗竴涓殑鎸夐挳
*/
Album: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
Album: null,
startUp: null,
}, config);
}
var div = document.createElement('div');
div.innerHTML = '
';
div.className = "_AlbumPictures";
var bo = document.body;
bo.insertBefore(div, bo.lastChild);
var $Album = document.getElementsByClassName('_AlbumPictures')[0],
$photoImg = document.getElementById('_photoImg'),
$SBL = document.getElementsByClassName('_SBL')[0],
$SBR = document.getElementsByClassName('_SBR')[0],
$infobar = document.getElementsByClassName('infobar')[0],
$objliArray=config.Album.getElementsByClassName('li')
var liIndex = 0,
lilenght = $objliArray.length - 1,
parentLi;
//鐪嬪ぇ鍥
for (var i = 0; i <= lilenght; i++) {
$objliArray[i].index=i
$objliArray[i].onclick = function (e) {
clickEvent(i,this)
e.stopPropagation();
}
}
config.startUp && (
config.startUp.onclick=function(e){
clickEvent(0,$objliArray[0])
}
)
function clickEvent(liIndex,e) {
$SBL.style = "display: block;"
$SBR.style = "display: block;"
parentLi = e
$Album.className = '_AlbumPictures active';
console.log(e)
$photoImg.src = parentLi.getAttribute('data-url')
liIndex = parentLi.index
$infobar.innerHTML = (liIndex + 1) + '/' + (lilenght + 1)
if (liIndex == lilenght) {
$SBR.style = "display: none;"
} else if (liIndex == 0) {
$SBL.style = "display: none;"
}
}
var $swiperBtnOff = document.getElementsByClassName('_swiperBtnOff')[0];
//鍏抽棴
$swiperBtnOff.addEventListener('click', function (e) {
$Album.className = '_AlbumPictures';
});
//宸﹀垏鎹
$SBL.addEventListener('click', function (e) {
liIndex <= 0 ? liIndex = 0 : liIndex--;
if (liIndex == 0) {
$SBL.style = "display: none;";
} else {
$SBR.style = "display: block;";
}
$photoImg.style = 'transform: translate(0%,-50%);opacity: 0;transition: ease .5s;'
$photoImg.addEventListener('transitionend', fnOut, false)
e.stopPropagation();
})
//鍙冲垏鎹
$SBR.addEventListener('click', function (e) {
liIndex == lilenght ? liIndex = lilenght : liIndex++;
if (liIndex == lilenght) {
$SBR.style = "display: none;";
} else {
$SBL.style = "display: block;";
}
$photoImg.style = 'transform: translate(-100%,-50%);opacity: 0;transition: ease .5s'
$photoImg.addEventListener('transitionend', fnOut, false)
e.stopPropagation();
})
function fnOut(e) {
$photoImg.style = 'transform: translate(-50%,-50%);opacity:1;transition:opacity ease .5s;'
$photoImg.src = $objliArray[liIndex].getAttribute('data-url')
$infobar.innerHTML = (liIndex + 1) + '/' + (lilenght + 1)
e.stopPropagation();
}
},
/**
*鍔犺浇浜嬬墿鐨勭櫨鍒嗘瘮(鏃犳硶鍒ゆ柇鑳屾櫙)
*
* @param {*} $obj 鎺ユ敹鍔犺浇杩涘害
* @param {*} $Loader 鍔犺浇浜嬬墿
* @return {*} callback
*/
LoadPercentage: function (config, callback) {
if (Object.assign != undefined) {
config = Object.assign({
obj: null,
Loader: null,
timer: 1000
}, config);
}
var $Loader, len = 0;
var $Loader = util.ifIDorClass(config.Loader)
var $obj = util.ifIDorClass(config.obj)
//console.log( util.ifIDorClass(config.out))
if (($Loader == null) || ($obj == null)) return
for (var i = 0; i < $Loader.length; i++) {
(function (i) {
if ($Loader[i].tagName == 'VIDEO') {
$Loader[i].oncanplaythrough
len++
doIt(len)
//oncanplaythrough
} else if ($Loader[i].tagName == 'IMG') {
$Loader[i].src = $Loader[i].getAttribute('minsrc-data')
if ($Loader[i].complete) {
len++;
doIt(len)
} else {
$Loader[i].onload = function () {
len++;
doIt(len)
}
}
}
})(i);
}
function doIt(len) {
var num = Math.round(len * 100 / $Loader.length)
$obj[0].innerHTML = Math.round(len * 100 / $Loader.length) + '%';
if (len == $Loader.length) {
var deadLine = false;
onLoad()
setTimeout(function () {
deadLine = true;
}, config.timer); //鏈€灏忓睍绀烘椂闂达紝绀轰緥涓?绉
function onLoad() {
if (deadLine) {
isCallback() && (callback(num))
} else {
setTimeout(onLoad, 1000); // 杩樻病鏈夊埌鏈€灏忓睍绀烘椂闂达紝1绉掑悗閲嶈瘯
}
}
}
}
//isCallback 鏄惁鏈夎繑鍥炲€
function isCallback() {
return callback == undefined ? false : true
}
},
/**
* 鏂板缓toast鎻愮ず妗
*
*/
toastInit: function () {
var $body = document.getElementsByTagName('body')[0];
var toastHTML = document.createElement('div');
toastHTML.innerHTML = '
';
toastHTML.className = "_toast";
$body.appendChild(toastHTML);
},
/**
*鍩虹鐗坆anner
*
* @param {*} $banner banner 鍒濆
* @param {*} $btnR 鎸夐挳R
* @param {*} $btnL 鎸夐挳L
* @param {*} $pagination 鍒嗛〉鍣ㄥ皬鐐
* @param {Number} timer 鑷姩鍒囨崲鏃堕棿 榛樿5s
* @param {string} effect 鍒囨崲鏁堟灉
* @param {Booleans} autoplay 鑷姩鍒囨崲锛岄粯璁ゅ叧闂
* @param {Booleans} bannerBtnLR banner 宸﹀彸涓ょ増鍒囨崲锛岄粯璁ゅ叧闂
* @param {Booleans} progressBar 鏄惁杩涘害鏉?鏈€濂藉湪鑷姩鎾斁寮€鍚椂鍦ㄥ紑鍚痯rogressBar
* @param {Booleans} loop 鏄惁寰幆锛岄粯璁ゅ叧闂
* @return {*} callback
*/
banner: function (config, callback) {
if (Object.assign != undefined) {
config = Object.assign({
$banner: null,
$btnR: null,
$btnL: null,
$pagination: null,
speed: 3,
timer: 5,
effect: '',
autoplay: false,
bannerBtnLR: false,
progressBar: false,
loop: false,
}, config);
}
var AnimationEnd = true
var callbackData = {
bannerIndex: 0
}
var _w = document.body.clientWidth,
_h = window.innerHeight
var $li = config.$banner.children[0].children,
bannerLen = $li.length - 1;
var indexAll = {
index: 0,
nextIndex: 1,
prevIndex: bannerLen
}
if (bannerLen == 0) {
return
}
//isCallback 鏄惁鏈夎繑鍥炲€
function isCallback() {
return callback == undefined ? false : true
}
config.$pagination && InitPagination(config);
config.progressBar && InitProgressBar(config);
util.addClass($li[indexAll.index], 'active')
util.addClass($li[1], 'activeNext')
var bannerInterval
config.autoplay && foo(config, indexAll)
effectInit(config, indexAll)
bannerSwBtn(config)
loopInit(config)
//寰幆
function loopInit(config) {
}
//banner 鍒囨崲鐐
function InitPagination(param) {
var objAble = '';
for (var i = 0; i <= bannerLen; i++) {
objAble += ''
}
config.$pagination.innerHTML = objAble, util.addClass(config.$pagination.children[0], 'active')
}
//杩涘害鏉
function InitProgressBar(config) {
var objProgressBar = document.createElement('div');
objProgressBar.className = "_progressBar";
config.$banner.appendChild(objProgressBar)
}
//杩涘害鏉″姩鐢
function AnimProgressBar(config, status) {
var $progressBar = document.getElementsByClassName('_progressBar')[0];
if (status == 'start') {
util.addClass($progressBar, 'active')
TweenMax.to($progressBar, config.timer, {
width: 100 + '%',
onComplete: function (e) {
}
});
} else {
util.removeClass($progressBar, 'active')
TweenMax.set($progressBar, {
width: 0,
onComplete: function (e) {
}
});
}
}
// 姝e父寰幆鍒囨崲banner
function foo(config, indexAll) {
if (AnimationEnd) {
clearInterval(bannerInterval)
config.progressBar && AnimProgressBar(config, 'start')
bannerInterval = setTimeout(function () {
Object.keys($li).forEach(function (i, item) {
util.removeClass($li[i], 'active')
util.removeClass($li[i], 'activeNext')
util.removeClass($li[i], 'activePrev')
config.$pagination && (util.removeClass(config.$pagination.children[i], 'active'))
})
indexAll.index >= bannerLen ? indexAll.index = 0 : indexAll.index++
callbackData.bannerIndex = indexAll.index
indexAll.prevIndex = (indexAll.index - 1) < 0 ? (bannerLen) : (indexAll.index - 1)
indexAll.nextIndex = (indexAll.index + 1) > bannerLen ? 0 : indexAll.index + 1
if (config.effect == 'mask') {
$li[indexAll.prevIndex].style = 'z-index:1'
}
effectF(config, indexAll, 'R')
isCallback() && (callback(callbackData))
util.addClass($li[indexAll.index], 'active')
util.addClass($li[indexAll.nextIndex], 'activeNext')
util.addClass($li[indexAll.prevIndex], 'activePrev')
config.$pagination && (util.addClass(config.$pagination.children[indexAll.index], 'active'))
foo(config, indexAll)
}, (config.timer * 1000));
}
}
//浜嬩欢鎵ц鍚庡垏鎹anner锛屽悗鎵цfoo 姝e父鍒囨崲
function fooC(config, indexAll, BtnLRtype) {
config.progressBar && AnimProgressBar(config, 'end')
isCallback() && (callback(callbackData))
Object.keys($li).forEach(function (i, item) {
util.removeClass($li[i], 'active')
util.removeClass($li[i], 'activeNext')
util.removeClass($li[i], 'activePrev')
config.$pagination && (util.removeClass(config.$pagination.children[i], 'active'))
})
indexAll.prevIndex = (indexAll.index - 1) < 0 ? (bannerLen) : (indexAll.index - 1)
indexAll.nextIndex = (indexAll.index + 1) > bannerLen ? 0 : indexAll.index + 1
effectF(config, indexAll, BtnLRtype)
util.addClass($li[indexAll.index], 'active')
util.addClass($li[indexAll.nextIndex], 'activeNext')
util.addClass($li[indexAll.prevIndex], 'activePrev')
config.$pagination && (util.addClass(config.$pagination.children[indexAll.index], 'active'))
}
//鑷畾涔夋晥鏋滃垵濮嬪寲
function effectInit(config, indexAll) {
if (config.effect == 'brush') {
util.addClass(config.$banner.children[0], 'brush')
//util.addClass(config.$banner.children[0], '_h100vh')
config.$banner.children[0].children[0].style = 'width:100%';
for (var i = 0; i <= bannerLen; i++) {
config.$banner.children[0].children[i].children[0].style.width = _w + 'px'
}
} else if (config.effect == '??') {
for (var i = 0; i <= bannerLen; i++) {
config.$banner.children[0].children[i].style.transform = "translate3d(" + (-i * config.$banner.clientWidth) + "px, 0px, 0px)"
}
} else if (config.effect == 'mask') {
util.addClass(config.$banner.children[0], 'mask')
for (var i = 0; i <= bannerLen; i++) {
var liHtml = config.$banner.children[0].children[i].innerHTML
config.$banner.children[0].children[i].innerHTML = '' + liHtml + '
';
$li[i].children[0].style = 'clip-path:polygon(0% 40%,0% 40%,0% 60%,0 60%)'
}
$li[0].children[0].style = 'clip-path:polygon(0% 0%,100% 0%,100% 100%,0 100%)'
config.$btnR && config.$btnL && (
config.$btnL.onmouseenter = function () {
$li[indexAll.index].style = 'z-index:1'
TweenMax.to($li[indexAll.prevIndex].children[0], .6, {
autoCSS: false,
startAt: {
'clip-path': 'polygon(0% 40%,0% 40%,0% 60%,0 60%)',
},
css: {
'clip-path': 'polygon(0% 40%,10% 40%,10% 60%,0 60%)',
},
onComplete: function (e) {
}
});
},
config.$btnL.onmouseleave = function () {
TweenMax.to($li[indexAll.prevIndex].children[0], .3, {
autoCSS: false,
css: {
'clip-path': 'polygon(0% 40%,0% 40%,0% 60%,0 60%)',
},
onComplete: function (e) {
$li[indexAll.index].style = 'z-index:2'
}
});
},
config.$btnR.onmouseenter = function (e) {
$li[indexAll.index].style = 'z-index:1'
TweenMax.to($li[indexAll.nextIndex].children[0], .6, {
autoCSS: false,
startAt: {
'clip-path': 'polygon(100% 40%,100% 40%,100% 60%,100% 60%)',
//'z-index':'9'
},
css: {
'clip-path': 'polygon(90% 40%,100% 40%,100% 60%,90% 60%)',
},
onComplete: function (e) {
}
});
},
config.$btnR.onmouseleave = function (e) {
TweenMax.to($li[indexAll.nextIndex].children[0], .3, {
autoCSS: false,
css: {
'clip-path': 'polygon(100% 40%,100% 40%,100% 60%,100% 60%)',
},
onComplete: function (e) {
$li[indexAll.index].style = 'z-index:2'
}
});
}
)
}
}
//鏁堟灉鍒囨崲
function effectF(config, indexAll, BtnLRtype) {
if (config.effect == '') {
AnimationEnd = false
TweenMax.to(config.$banner.children[0], config.speed, {
x: (-indexAll.index * config.$banner.clientWidth),
onComplete: function (e) {
AnimationEnd = true
config.autoplay && foo(config, indexAll)
config.progressBar && AnimProgressBar(config, 'end')
}
});
//config.$banner.children[0].style.transform = ""
} else if (config.effect == 'brush') {
AnimationEnd = false
TweenMax.to(config.$banner.children[0].children[indexAll.index], config.speed, {
autoCSS: false,
css: {
width: _w,
},
onComplete: function (e) {
AnimationEnd = true
config.autoplay && foo(config, indexAll)
config.progressBar && AnimProgressBar(config, 'end')
}
});
for (var i = 0; i <= bannerLen; i++) {
if (i != indexAll.index) {
TweenMax.to(config.$banner.children[0].children[i], config.speed, {
autoCSS: false,
css: {
width: 0,
},
});
}
}
} else if (config.effect == 'mask') {
if (BtnLRtype == 'R') {
$li[indexAll.prevIndex].style.zIndex = '1'
TweenMax.to($li[indexAll.index].children[0], .6, {
autoCSS: false,
startAt: {
'clip-path': 'polygon(90% 40%,100% 40%,100% 60%,90% 60%)',
},
css: {
'clip-path': 'polygon(0% 40%,100% 40%,100% 60%,0% 60%)',
},
onComplete: function (e) {
TweenMax.to($li[indexAll.index].children[0], .6, {
startAt: {
'clip-path': 'polygon(0% 40%,100% 40%,100% 60%,0% 60%)',
},
css: {
'clip-path': 'polygon(0% 0%,100% 0%,100% 100%,0% 100%)',
},
onComplete: function (e) {
$li[indexAll.prevIndex].style = 'z-index:2';
$li[indexAll.nextIndex].style = 'z-index:2';
$li[indexAll.index].style = 'z-index:2';
$li[indexAll.prevIndex].children[0].style = 'clip-path:polygon(0% 40%,0% 40%,0% 60%,0 60%)'
$li[indexAll.nextIndex].children[0].style = 'clip-path:polygon(0% 40%,0% 40%,0% 60%,0 60%)';
config.autoplay && foo(config, indexAll)
}
})
}
});
} else {
$li[indexAll.nextIndex].style.zIndex = '1'
TweenMax.to($li[indexAll.index].children[0], .6, {
autoCSS: false,
css: {
'clip-path': 'polygon(0% 40%,100% 40%,100% 60%,0% 60%)',
},
onComplete: function (e) {
TweenMax.to($li[indexAll.index].children[0], .6, {
startAt: {
'clip-path': 'polygon(0% 40%,100% 40%,100% 60%,0% 60%)',
},
css: {
'clip-path': 'polygon(0% 0%,100% 0%,100% 100%,0% 100%)',
},
onComplete: function (e) {
$li[indexAll.prevIndex].style = 'z-index:2';
$li[indexAll.nextIndex].style = 'z-index:2';
$li[indexAll.index].style = 'z-index:2';
$li[indexAll.prevIndex].children[0].style = 'clip-path:polygon(0% 40%,0% 40%,0% 60%,0 60%)'
$li[indexAll.nextIndex].children[0].style = 'clip-path:polygon(0% 40%,0% 40%,0% 60%,0 60%)'
config.autoplay && foo(config, indexAll)
}
})
}
});
}
}
}
//banner 宸﹀彸涓ょ増闈㈠垏鎹
function bannerSwBtn(config) {
if (config.bannerBtnLR) {
//config.$banner.innerHTML=''
var $swiperPrer = document.createElement('div'),
$swiperNext = document.createElement('div');
$swiperPrer.className = "_swiperPrer bannerSwBtn";
$swiperNext.className = "_swiperNext bannerSwBtn";
config.$banner.appendChild($swiperPrer);
config.$banner.appendChild($swiperNext);
$swiperPrer.addEventListener('click', bannerBtnL)
$swiperNext.addEventListener('click', bannerBtnR)
}
}
//宸﹀彸鎸夐挳鍒囨崲
function bannerBtnL() {
if (AnimationEnd) {
clearInterval(bannerInterval)
indexAll.index = callbackData.bannerIndex
indexAll.index <= 0 ? indexAll.index = bannerLen : indexAll.index--
callbackData.bannerIndex = indexAll.index
fooC(config, indexAll, 'L')
}
}
function bannerBtnR() {
if (AnimationEnd) {
clearInterval(bannerInterval)
indexAll.index = callbackData.bannerIndex
indexAll.index >= bannerLen ? indexAll.index = 0 : indexAll.index++
callbackData.bannerIndex = indexAll.index
fooC(config, indexAll, 'R')
}
}
// 鍒囨崲banner
config.$btnR && config.$btnL && (
config.$btnR.addEventListener('click', bannerBtnR),
config.$btnL.addEventListener('click', bannerBtnL)
)
config.$pagination && (
config.$pagination.addEventListener('click', function (e) {
var event = e || window.event;
var target = event.target || event.srcElement;
if (AnimationEnd) {
var lists = Array.from(config.$pagination.querySelectorAll('span'));
indexAll.index = lists.indexOf(target)
if (indexAll.index != -1) {
callbackData.index = indexAll.index
clearInterval(bannerInterval)
fooC(config, indexAll)
}
}
})
)
},
shineText: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
$obj: null,
}, config);
}
var _textContent = config.$obj.getAttribute('data-text'),
$body = document.getElementsByTagName('body')[0];
//shine-wrapper
config.$obj.innerHTML = '
'
var FontSpan = '',
$shineWord = document.getElementsByClassName('_shineWord')[0],
$shineMask = document.getElementsByClassName('_shineMask')[0]
var Mouse = {
x: 0,
y: 0
},
textXy = []
for (var i = 0; i <= _textContent.length - 1; i++) {
FontSpan += '' + _textContent[i] + ''
}
$shineWord.innerHTML = FontSpan
$shineMask.innerHTML = FontSpan
// init()
// function init() {
// requestAnimationFrame(render)
// }
// function render() {
// for (var i = 0; i <= _textContent.length - 1; i++) {
// //$shineWord.children[i]
// }
// init()
// }
// $body.onmousemove = function (event) {
// var e = event || window.event
// //鑾峰彇榧犳爣鐨勫潗鏍
// Mouse.x = e.clientX
// Mouse.y = e.clientY
// for (var o = [], r = 0; r < config.numSteps; r++) {
// var a = r / config.numSteps
// , s = Math.pow(a, config.opacityPow)
// , l = Math.pow(a, config.offsetPow)
// , c = Math.pow(a, config.blurPow)
// , u = e.Math.max(0, config.opacity * (1 - s))
// , d = -config.offset * Mouse.x * l
// , p = -config.offset * Mouse.y * l
// , f = i * config.blur * c / 512
// , m = getShadow(config.shadowRGB, u, d, p, f);
// o.push(m)
// //console.log(o)
// //$shineWord.childNodes[a].style=o[r]
// }
// //console.log(o)
// //drawShadows(o)
// }
function getShadow(e, t, n, i, o) {
return "rgba(" + 0 + ", " + 0 + ", " + 0 + ", " + t + ") " + n + "px " + i + "px " + Math.round(o) + "px"
}
function drawShadows(o) {
for (var i = 0; i <= _textContent.length - 1; i++) {
// $shineWord.childNodes[i].style=o[i].join(", ")
}
}
},
/**
*鍒涢€犲悎鎴愬浘鐗
*
* @param {*} $cntElem 鍒涢€犲悗鏄剧ず璺緞
* @param {*} $CreationSrc 鍒涢€犲悗鏄剧ず璺緞
*/
createImg: function (config, callback) {
if (Object.assign != undefined) {
config = Object.assign({
$cntElem: null,
}, config);
}
// 杩涜canvas鐢熸垚
var shareContent = config.$cntElem; //闇€瑕佹埅鍥剧殑鍖呰9鐨勶紙鍘熺敓鐨勶級DOM 瀵硅薄
var width = shareContent.offsetWidth; //鑾峰彇dom 瀹藉害
var height = shareContent.offsetHeight; //鑾峰彇dom 楂樺害
var canvas = document.createElement("canvas"); //鍒涘缓涓€涓猚anvas鑺傜偣
var scale = 2; //瀹氫箟浠绘剰鏀惧ぇ鍊嶆暟 鏀寔灏忔暟
canvas.width = width * scale; //瀹氫箟canvas 瀹藉害 * 缂╂斁
canvas.height = height * scale; //瀹氫箟canvas楂樺害 *缂╂斁
canvas.getContext("2d").scale(scale, scale); //鑾峰彇context,璁剧疆scale
var opts = {
scale: scale, // 娣诲姞鐨剆cale 鍙傛暟
canvas: canvas, //鑷畾涔 canvas
// logging: true, //鏃ュ織寮€鍏筹紝渚夸簬鏌ョ湅html2canvas鐨勫唴閮ㄦ墽琛屾祦绋
width: width, //dom 鍘熷瀹藉害
height: height,
useCORS: true // 銆愰噸瑕併€戝紑鍚法鍩熼厤缃
};
html2canvas(shareContent, opts).then(function (canvas) {
var context = canvas.getContext('2d');
// 銆愰噸瑕併€戝叧闂姉閿娇
context.mozImageSmoothingEnabled = true;
context.webkitImageSmoothingEnabled = true;
context.msImageSmoothingEnabled = true;
context.imageSmoothingEnabled = true;
// 銆愰噸瑕併€戦粯璁よ浆鍖栫殑鏍煎紡涓簆ng,涔熷彲璁剧疆涓哄叾浠栨牸寮
var img = Canvas2Image.convertToJPEG(canvas, canvas.width, canvas.height);
var IMG = img.src
isCallback() && (callback(IMG))
});
//isCallback 鏄惁鏈夎繑鍥炲€
function isCallback() {
return callback == undefined ? false : true
}
},
/**
*椤甸潰璺宠浆
* @param {*} $PageTurningNumber 缈婚〉鐖剁骇div
* @param {Number} page 褰撳墠椤垫暟
* @param {Number} PageSize 涓€椤垫潯鏁
* @param {Number} count 鎬绘潯鏁
* @param {*} php php鍐欐硶閾炬帴 green_140.html?page=
* @param {*} keywords 鍏抽敭瀛 green_140.html?page=1&keywords=涓
*/
PageTurningNumber: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
$PageTurningNumber: null,
page: 1,
pageSize: 4,
count: 100,
php: util.truncate(0, window.location.pathname, window.location.pathname.length - 5),
keywords: ''
}, config);
}
var liet = '',
initial = 1,
last = Total(config.count)
if (last == 0) {
return
}
config.page = Number(config.page)
config.$PageTurningNumber.innerHTML = '棣栭〉灏鹃〉璺宠浆鍒?椤袋a class="_btnJump" href="javascript:void(0)">纭畾鍏? + Total(config.count) + '椤袋/span>'
var $pageNumber = document.getElementsByClassName('pageNumber')[0],
$btnJump = document.getElementsByClassName('_btnJump')[0],
$Incoming = document.getElementsByClassName('_Incoming')[0]
console.log('?')
config.page - 2 <= 1 ? initial = 1 : initial = config.page - 2
config.page + 2 >= last ? last = Total(config.count) : last = config.page + 2
for (i = initial; i <= last; i++) {
liet += '' + i + ''
}
$pageNumber.innerHTML = liet
function Total(n) {
return Math.ceil(n / config.pageSize)
}
function active(i) {
return config.page == i ? 'active' : ''
}
$btnJump.addEventListener('click', function (e) {
if ($Incoming.value > Total(config.count) || (!util.regNumber($Incoming.value))) {
return
}
window.location.href = config.php + '/' + $Incoming.value + '.html' + config.keywords
})
},
/**
* 杩斿洖椤堕儴 璋冪敤 scrollToTop
*/
backTop: function () {
var offset = 300,
offset_opacity = 200,
scroll_top_duration = 500
var $body = document.getElementsByTagName('body')[0],
$backTop = document.createElement('div');
$backTop.className = "backTop animate _iconfont";
$backTop.innerHTML = ''
$body.appendChild($backTop);
$backTop.addEventListener("click", function (e) {
util.scrollToTop()
})
window.onscroll = function () {
//鍙橀噺t鏄粴鍔ㄦ潯婊氬姩鏃讹紝璺濈椤堕儴鐨勮窛绂
var t = document.documentElement.scrollTop || document.body.scrollTop;
var scrollup = document.getElementById('scrollup');
//褰撴粴鍔ㄥ埌璺濈椤堕儴200px鏃讹紝杩斿洖椤堕儴鐨勯敋鐐规樉绀
if (t >= offset_opacity) {
util.addClass($backTop, 'active')
} else { //鎭㈠姝e父
util.removeClass($backTop, 'active')
}
}
},
scrollToTop: function () {
var c = document.documentElement.scrollTop || document.body.scrollTop;
if (c > 0) {
if (!window.requestAnimationFrame) {
window.scrollTo(0, c - c / 8);
util.scrollToTop()
} else {
window.requestAnimationFrame(util.scrollToTop);
window.scrollTo(0, c - c / 8);
}
}
},
/**
*鍒嗕韩
*
* @param {*} bdText 鏍囬
* @param {*} bdDesc 绠€浠
* @param {*} bdUrl 鍒嗕韩鐨勯摼鎺
*/
share: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
obj: null,
shareTitle: '',
shareSummary: '',
shareUrl: location.href,
sharePic: '',
shareSelect: ['']
}, config);
}
var wecnatInfo = {
wechatQrcodeTitle: "寰俊鎵竴鎵細鍒嗕韩",
wechatQrcodeHelper: "寰俊閲岀偣鈥滃彂鐜扳€濓紝鎵竴涓婞/p>
浜岀淮鐮佷究鍙皢鏈枃鍒嗕韩鑷虫湅鍙嬪湀銆侟/p>",
wechatQrcodeSize: 100,
},
select = {
qzone: "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" + config.shareUrl + "&title=" + config.shareTitle + "&summary=" + config.shareSummary + "&pics=" + config.sharePic,
qq: "http://connect.qq.com/widget/shareqq/index.html?url=" + config.shareUrl + "&title=" + config.shareTitle + "&summary=" + config.shareSummary + "&pics=" + config.sharePic,
weibo: "http://service.weibo.com/share/share.php?url=" + config.shareUrl + "&title=" + config.shareTitle + "&summary=" + config.shareSummary + "&pic=" + config.sharePic,
wechat: 'javascript:void(0)'
},
iconList = {
wechat: '',
weibo: '',
qzone: '',
qq: '',
}
var $obj = config.obj,
shareLi = ''
for (var i in config.shareSelect) {
if (config.shareSelect[i] == 'wechat') {
shareLi += '' + iconList[config.shareSelect[i]] + '寰俊鎵竴鎵細鍒嗕韩
寰俊閲岀偣鈥滃彂鐜扳€濓紝鎵竴涓婞/p>
浜岀淮鐮佷究鍙皢鏈枃鍒嗕韩鑷虫湅鍙嬪湀銆侟/p>
'
} else {
shareLi += '' + iconList[config.shareSelect[i]] + ''
}
}
$obj.innerHTML = shareLi
new QRCode(document.getElementById("qrcode"), config.shareUrl);
//http://service.weibo.com/share/share.php?url={url}&title={title}&pic={pic}&searchPic=false';
},
/**
*鐎戝竷娴
* @param {*} $ul 鍒楄〃鐖剁骇
* @param {Number} row 鍑犲垪
* @param {Number} border 杈硅窛
*/
waterfall: function (config) {
if (Object.assign != undefined) {
config = Object.assign({
$ul: '',
row: 4,
border: 20,
}, config);
}
var li_bottom = config.border
var $li = config.$ul.children;
var max_H = 0
function ul_begin(row) {
var h = [];
var li_W = (config.$ul.offsetWidth - (config.border * (row - 1))) / row;
var li_WB = (config.$ul.offsetWidth - (config.border * (row - 1))) / row + config.border;
for (var i = 0; i < $li.length; i++) {
config.$ul.children[i].style.width = li_W + 'px'
li_H = $li[i].offsetHeight + li_bottom;
if (i < row) {
h[i] = li_H;
$li[i].style.top = 0;
$li[i].style.left = i * li_W + 'px';
if ($li[i].offsetLeft != 0) {
$li[i].style.left = i * li_WB + 'px';
}
} else {
min_H = Math.min.apply(null, h);
minKey = getarraykey(h, min_H);
h[minKey] += li_H;
$li[i].style.top = min_H + 'px';
$li[i].style.left = minKey * li_W + 'px';
if ($li[i].offsetLeft != 0) {
//$li[i].style.left = i * li_WB + 'px';
$li[i].style.left = minKey * li_WB + 'px';
}
}
max_H = Math.max.apply(null, h);
}
config.$ul.style.height = max_H + 'px'
}
function getarraykey(s, v) {
for (k in s) {
if (s[k] == v) {
return k;
}
}
}
ul_begin(config.row);
window.onresize = function () {
if (document.body.clientWidth <= 1024 && document.body.clientWidth >= 768) {
row = 2
} else if (document.body.clientWidth < 768) {
row = 1
} else {
row = config.row
}
ul_begin(row);
};
window.onscroll= function(){
//鏂囨。鍐呭瀹為檯楂樺害锛堝寘鎷秴鍑鸿绐楃殑婧㈠嚭閮ㄥ垎锛
var scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
//婊氬姩鏉℃粴鍔ㄨ窛绂
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
//绐楀彛鍙鑼冨洿楂樺害
var clientHeight = window.innerHeight || Math.min(document.documentElement.clientHeight,document.body.clientHeight);
if(clientHeight + scrollTop >= scrollHeight){
console.log("===鍔犺浇鏇村鍐呭鈥︹€?==");
}
}
},
/************************************************************************
* 琛ㄥ崟鍒ゅ畾
************************************************************************/
/**
* 楠岃瘉鎵嬫満鍙风爜
*
* @param {Number} 浼犲叆鐨勬墜鏈哄彿鐮
* @return true||false
*/
regPhone: function (phone) {
reg = /^(13|15|17|18|19|14)[0-9]{9}$/;
return reg.test(phone);
},
/**
*楠岃瘉鏁板瓧
*
* @param {Number} number 鏁板瓧
* @return true||false
*/
regNumber: function (number) {
reg = /^[0-9]*$/;
return reg.test(number);
},
/**
* 濮撳悕 || 鍙兘杈撳叆涓嫳鏂
* @param {String} 鍚嶅瓧
* @return true||false
*/
regName: function (name) {
reg = /^[\u4E00-\u9FA5A-Za-z]+$/;
return reg.test(name);
},
/**
*
*鍒ゆ柇韬唤璇佸彿鐮佹槸鍚︾鍚堣姹
* @param {Number} IDcard 韬唤璇
* @return true||false
*/
regID: function (IDcard) {
reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
return reg.test(IDcard);
},
/**
*
*鍒ゆ柇閭绗﹀悎瑕佹眰
* @param {Number} IDcard 韬唤璇
* @return true||false
*/
regEmail: function (Email) {
reg = /^\w+\@+[0-9a-zA-Z]+\.(com|com.cn|edu|hk|cn|net)$/;
return reg.test(Email);
},
/**
*鍒ゅ畾鏄惁绌烘垨鑰呯┖鏍
*
* @param {*} Null
*/
regNull: function (Null) {
if (Null == "") return true;
var regu = "^[ ]+$";
var re = new RegExp(regu);
return re.test(Null);
},
/************************************************************************
* DOMs 鑺傜偣
************************************************************************/
/**
*鍒ゆ柇鏄痗lass 杩樻槸id
* @param {*} ele 鍒ゅ畾鐨刣om
* @returns 杩斿洖瀵瑰簲鐨勯澶囧畾涔
*/
ifIDorClass: function (ele) {
if (ele == null) {
return false
} else if (ele.indexOf('.') == 0) {
return document.getElementsByClassName(ele.substr(1))
} else if (ele.indexOf('#') == 0) {
return document.getElementById(ele.substr(1))
}
},
/**
*鍒ゅ畾鏄惁鏈塩lass
*
* @param {*} ele 鍒ゅ畾鐨刣om
* @param {String} cls 鍒ゅ畾鐨刢lass
* @return true||false
*/
hasClass: function (ele, cls) {
return ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
},
/**
*涓烘寚瀹氱殑dom鍏冪礌娣诲姞鏍峰紡
*
* @param {*} ele 鎸囧畾鐨刣om
* @param {String} cls 娣诲姞鐨刢lass
*/
addClass: function (ele, cls) {
if (!util.hasClass(ele, cls)) ele.className += " " + cls;
},
/**
*鍒犻櫎鎸囧畾dom鍏冪礌鐨勬牱寮
*
* @param {*} ele 鎸囧畾鐨刣om
* @param {String} cls 鍒犻櫎鐨刢lass
*/
removeClass: function (ele, cls) {
if (util.hasClass(ele, cls)) {
var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
ele.className = ele.className.replace(reg, "");
}
},
/**
*鎸囧畾dom娣诲姞鍜屽垹闄ょ浉鍚宑lass
*
* @param {*} ele
* @param {*} cls
*/
toggleClass: function (ele, cls) {
if (util.hasClass(ele, cls)) {
util.removeClass(ele, cls);
} else {
util.addClass(ele, cls);
}
},
/************************************************************************
* browser娴忚鍣
************************************************************************/
/**
* // 鑾峰彇 url 涓殑鍙傛暟鍊
*
* @param {*} name 闇€瑕佽幏鍙栫殑鍙傛暟鍚
* @returns 鍊 || null
*/
getSearch: function (name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
return r ? decodeURIComponent(r[2]) : null;
},
/**
* 鍒ゅ畾璁块棶绫诲瀷鏄數鑴戣繕鏄Щ鍔ㄧ
* @returns 杩斿洖璁块棶绫诲瀷
*/
userAgent: function (e) {
if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
/*window.location.href="浣犵殑鎵嬫満鐗堝湴鍧€";*/
return 'Mobile'
} else {
/*window.location.href="浣犵殑鐢佃剳鐗堝湴鍧€"; */
return 'pc'
}
},
/************************************************************************
* 鏃ユ湡绫
************************************************************************/
/**
*鏃堕棿鎴
*
* @param {Number} timestamp 鏃堕棿鎴
* @returns 杞崲鎴愮殑鏃堕棿
*
* Conversion[] 杞彉鍚庣殑鏃堕棿
* Remaining[] 杞彉鍚庡埌瀹為檯
*/
CountdownNumber: function (timestamp) {
var timeBox = {
Conversion: [],
Remaining: []
}
var difference = 0
var currentTimer = Math.floor(new Date().getTime() / 1000);
var dd_ = 0,
hh_ = 0,
mm_ = 0,
ss_ = 0;
difference = timestamp - currentTimer;
dd_ = Math.floor(difference / (60 * 60 * 24)); //璁$畻鍓╀綑鐨勫ぉ鏁
hh_ = Math.floor(difference / (60 * 60)) - (dd_ * 24) //璁$畻鍓╀綑鐨勫皬鏃舵暟
mm_ = Math.floor(difference / 60) - (dd_ * 24 * 60) - (hh_ * 60) //璁$畻鍓╀綑鐨勫垎閽熸暟
ss_ = Math.floor(difference) - (dd_ * 24 * 60 * 60) - (hh_ * 60 * 60) - (mm_ * 60) //璁$畻鍓╀綑鐨勭鏁
if (hh_ <= 9) hh_ = '0' + hh_;
if (mm_ <= 9) mm_ = '0' + mm_;
if (ss_ <= 9) ss_ = '0' + ss_;
var time = new Date(timestamp * 1000)
timeBox.Conversion.Year = time.getFullYear()
timeBox.Conversion.Month = time.getMonth()
timeBox.Conversion.Date = time.getDate()
timeBox.Conversion.Hours = time.getHours()
timeBox.Conversion.Minutes = time.getMinutes()
timeBox.Remaining.day = dd_
timeBox.Remaining.Hours = hh_
timeBox.Remaining.Minutes = mm_
timeBox.Remaining.second = ss_
return timeBox
},
/************************************************************************
* 瀛楃涓茬被
************************************************************************/
// 鎴彇缁欏畾闀垮害鐨勫瓧绗︿覆
truncate: function (str, string, len) {
if (string.length > len) {
string = string.substring(str, len);
}
return string;
},
/************************************************************************
* 绉诲姩绔棶棰
************************************************************************/
/**
* 琛ㄥ崟鎶栧姩
*
* @param {*} e
* @retyrbs 鐢ㄤ簬鍏ㄥ睆琛ㄥ崟锛岄敭鐩樺脊鍑哄悗锛岄€€鍑哄鑷磇nput閿欎綅
*/
inputShakeIos: function (e) {
document.body.addEventListener('focusin', function () {
//杞敭鐩樺脊鍑虹殑浜嬩欢澶勭悊
isReset = false;
});
document.body.addEventListener('focusout', function () {
//杞敭鐩樻敹璧风殑浜嬩欢澶勭悊
isReset = true;
setTimeout(function () {
//褰撶劍鐐瑰湪寮瑰嚭灞傜殑杈撳叆妗嗕箣闂村垏鎹㈡椂鍏堜笉褰掍綅
if (isReset) {
window.scroll(0, 0); //澶辩劍鍚庡己鍒惰椤甸潰褰掍綅
}
}, 300);
});
},
/**
* 琛ㄥ崟鎶栧姩
*
* @param {*} e
* @retyrbs 鐢ㄤ簬鍏ㄥ睆琛ㄥ崟锛岄敭鐩樺脊鍑哄悗锛岄€€鍑哄鑷磇nput閿欎綅
*/
inputShakeAndroid: function (e) {
window.onresize = function () {
//閿洏寮硅捣涓庨殣钘忛兘浼氬紩璧风獥鍙g殑楂樺害鍙戠敓鍙樺寲
var resizeHeight = document.documentElement.clientHeight || document.body.clientHeight;
if (resizeHeight < h) {
//褰撹蒋閿洏寮硅捣锛屽湪姝ゅ鎿嶄綔
isReset = false;
} else {
//褰撹蒋閿洏鏀惰捣锛屽湪姝ゅ鎿嶄綔
isReset = true;
setTimeout(function () {
if (isReset) {
window.scroll(0, 0); //澶辩劍鍚庡己鍒惰椤甸潰褰掍綅
}
}, 300);
}
};
},
/************************************************************************
* 鍏朵粬
************************************************************************/
/**
*闃叉iframe宓屽
*
*/
isTop: function () {
var isInTest = false
if (sessionStorage || window.sessionStorage) {
if (window.location.search) {
if (window.location.search.indexOf('isInTest') !== -1) {
sessionStorage.setItem('isInTest', true)
}
}
isInTest = Boolean(sessionStorage.getItem('isInTest'))
}
},
/**
* 铚€缇庨」鐩洃鎺
*/
shuwonProject: function () {
if (/shuwon/.test(location.search) || sessionStorage.getItem('debugger') == '12345677') {
sessionStorage.setItem("debugger", "12345677");
} else {
$.post("http://project.shuwon.cn/api/project/stop", {
url: location.origin
}, function (data) {
if (data.result) window.location.href = "http://www.shuwon.com/over/";
})
}
},
}
}
return util;
//}
})));