zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    GridView中绑定日期字段格式的定义《收集》
    纯代码实现GridView绑定增删改
    开发人员一定要加入收藏夹的网站《收藏》
    ASP.NET 2.0 创建母版页导致js出现“ 'document.getElementById(...)' 为空或不是对象”错误《转》
    ModelSim SE 6.5破解
    [转载]ZIGBEE:Coordinator中的邻居表(Neighbour Table)问题
    【转载】在ZigBee网络中实现节电断电之后重新加入网络
    Zstack 串口的使用
    PAN_ID
    ZigBee四种绑定 在TI ZStack和谈栈中应用
  • 原文地址:https://www.cnblogs.com/zhaofeis/p/12797996.html
Copyright © 2011-2022 走看看