• animation.js


    const Animation = {
    // 中奖排行榜ranking('meque', 'meque_text', -1)
    ranking (meques, text, speed) {
    let [
    mequeText = document.getElementById(text),
    meque = document.getElementById(meques),
    timer = null
    ] = []
    if (parseInt(this.getStyle(mequeText, 'height')) < parseInt(this.getStyle(meque, 'height'))) {
    return false
    }
    mequeText.innerHTML = mequeText.innerHTML + mequeText.innerHTML
    clearInterval(timer)
    timer = setInterval(notice, 40)
    notice()
    function notice () {
    if (mequeText.offsetTop < -mequeText.offsetHeight / 2) {
    mequeText.style.top = 0
    }
    mequeText.style.top = mequeText.offsetTop + speed +'px'
    }
    mequeText.onmouseover = function () {
    clearInterval(timer)
    }
    mequeText.onmouseout = function () {
    timer = setInterval(notice, 40)
    }
    mequeText.onmousedown = function (ev) {
    var ev = ev || window.event
    var disY = ev.clientY - this.offsetTop
    mequeText.onmousemove = function (ev) {
    var ev = ev || window.event
    mequeText.style.top = ev.clientY - disY + 'px'
    }
    document.onmouseup = function () {
    mequeText.onmousemove = null
    }
    }
    },
    /*运动框架move(this,{height:111,200,opacity:30}, 8, fn)*/
    move (obj, json, speed, fn) {
    clearInterval(obj.timer)
    obj.timer = setInterval(() => {
    var mStop = true /*当所有的值都到达*/
    for (var attr in json) {
    /*取当前值*/
    var com = 0
    if (attr == 'opacity') {
    com = parseInt(parseFloat(this.getStyle(obj, attr)) * 100)
    } else {
    com = parseInt(this.getStyle(obj, attr))
    } /*计算速度*/
    var iSpeed = (json[attr] - com) / speed
    iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed) /*检测*/
    if (com != json[attr]) {
    mStop = false
    }
    if (attr == 'opacity') {
    obj.style.filter = 'alpha(opacity:' + (com + iSpeed) + ')'
    obj.style.opacity = (com + iSpeed) / 100
    } else {
    obj.style[attr] = com + iSpeed + 'px'
    }
    }
    if (mStop) {
    clearInterval(obj.timer)
    if (fn) {
    fn()
    }
    }
    }, 30)
    },
    // 滚动公告 notice('meque', 'meque_text', -1)
    notice (meques, text, speed) {
    let [
    mequeText = document.getElementById(text),
    meque = document.getElementById(meques),
    timer = null
    ] = []
    // console.log(this.getStyle(mequeText, 'width'))
    // console.log(this.getStyle(meque, 'width'))
    if (parseInt(this.getStyle(mequeText, 'width')) < parseInt(this.getStyle(meque, 'width'))) {
    return false
    }
    mequeText.style.left = meque.offsetWidth + 'px'
    clearInterval(timer);
    timer = setInterval(notice, 20);
    notice()
    function notice () {
    if (mequeText.offsetLeft < -mequeText.offsetWidth) {
    mequeText.style.left = meque.offsetWidth + 'px'
    }
    mequeText.style.left = mequeText.offsetLeft + speed +'px'
    }
    mequeText.onmouseover = function () {
    clearInterval(timer)
    }
    mequeText.onmouseout = function () {
    timer = setInterval(notice, 20)
    }
    mequeText.onmousedown = function (ev) {
    var ev = ev || window.event
    var disX = ev.clientX - this.offsetLeft
    mequeText.onmousemove = function (ev) {
    var ev = ev || window.event
    mequeText.style.left = ev.clientX - disX + 'px'
    }
    document.onmouseup = function () {
    mequeText.onmousemove = null
    }
    }
    },

    /*
    * 获取属性兼容ie,current
    */
    getStyle (obj,attr) {
    if (obj.currentStyle) {
    return obj.currentStyle[attr]
    } else {
    return getComputedStyle(obj, false)[attr]
    }
    },

    }

    export default Animation
  • 相关阅读:
    linux下批量转换文件
    linux的最简socket编程
    war包部署到tomcat
    linux 重命名文件和文件夹
    Thread类的常用方法
    java.lang.Integer.MAX_VALUE;这是什么意思?
    java中 在一个异常处理中什么语句块是可多个的
    oracle条件参数中 IN函数中的值最大只能为1000个
    oracle判断一个字段为空
    javascript 六种数据类型
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12797996.html
Copyright © 2020-2023  润新知