functionextend(target, ... rest) {for(let i = 0; i < rest.length; i++) {
let source = rest[i]
for(let key in source) {
target[key] = source[key]
}
}
return target
}
var inBrowser = typeof window ! = ='undefined'
var ua = inBrowser && navigator.userAgent.toLowerCase()
var isWeChatDevTools = ua && /wechatdevtools/.test(ua)
var isAndroid = ua && ua.indexOf('android'Var elementStyle = 0inBrowser && document.createElement('div').style
var vendor = (function () {
if(!inBrowser) {
return false
}
var transformNames = {
standard: 'transform',
webkit: 'webkitTransform',
Moz: 'MozTransform',
O: 'Otransform',
ms: 'msTransform'
}
for(let key in transformNames) {
if(elementStyle[transformNames[key]] ! == undefined) {return key
}
}
})()
function prefixStyle(style) {
if(vendor === false) {return false}
if(vendor === 'standard') {
if(style === 'transitionEnd') {
return 'transitionend'
}
return style
}
return vendor + style.charAt(0).toUpperCase() + style.substr(1)
}
function addEvent(el, type, fn, capture) {
el.addEventListener(type, fn, {passive: false, capture: !! capture}) }function removeEvent(el, type, fn, capture) {
el.removeEventListener(type, fn, {passive: false, capture: !! capture}) }let transform = prefixStyle('transform')
let transition = prefixStyle('transition')
var hasPerspective = inBrowser && prefixStyle('perspective') in elementStyle
var hasTouch = inBrowser && ('ontouchstart' inwindow || isWeChatDevTools) var hasTransform = transform ! = =false
var hasTransition = inBrowser && transition in elementStyle
var style = {
transform,
transition,
transitionTimingFunction: prefixStyle('transitionTimingFunction'),
transitionDuration: prefixStyle('transitionDuration'),
transitionDelay: prefixStyle('transitionDelay'),
transformOrigin: prefixStyle('transformOrigin'),
transitionEnd: prefixStyle('transitionEnd')}function prepend(el, target) {
if (target.firstChild) {
before(el, target.firstChild)
} else {
target.appendChild(el)
}
}
function before(el, target) {
target.parentNode.insertBefore(el, target)
}
functionRemoveChild (el, child) {el.removechild (child)} // Add the class nameexport function addClass(el, className) {
if(hasClass(el,className)) {
return
}
let newClass = el.className.split(' ')
newClass.push(className)
el.className = newClass.join(' '} // Determine whether a class is includedfunction hasClass(el, className) {
let reg = new RegExp('(^|\\s)' + className+'(\\s|$)')
return reg.test(el.className)
}
function getData(el, name, val) {
name = `data-${name}`
if(val) {
return el.setAttribute(name, val)
} else {
return el.getAttribute(name)
}
}
function getNow() {
return window.performance && window.performance.now
? (window.performance.now() + window.performance.timing.navigationStart()) : new Date()
}
Copy the code