zoukankan      html  css  js  c++  java
  • vue 工具函数的封装 时间格式化函数

    时间代码格式化工具函数的封装

    小伙伴们,多封点工具函数,多封装点公共组件,多写点公共样式,照顾下互联网行业的新人把。。。。~~~~~

    /** yyyymmdd(new Date) -> "2018-07-23" */
    export function yyyymmdd(date, delimiter = '-') {  // 曝光函数出去 在需要用得地方引入这个文件 { yyyymmdd } 这种方式引入 yyyymmdd() // 直接传入参数
    	const yyyy = date.getFullYear().toString(); 
    	const mm = (date.getMonth() + 1).toString();
    	const dd = date.getDate().toString();
    	return yyyy + delimiter + (mm[1] ? mm : `0${mm[0]}`)
    		+ delimiter + (dd[1] ? dd : `0${dd[0]}`);
    }
    

    滚动动画函数

    export function scroll_to(el, from = 0, to, duration = 500) {
    	function callback() {
    		return window.setTimeout(callback, 1000 / 60);
    	}
    
    	if (!window.requestAnimationFrame) {
    		window.requestAnimationFrame = (
    			window.webkitRequestAnimationFrame
    			|| window.mozRequestAnimationFrame
    			|| window.msRequestAnimationFrame
    			|| callback
    		);
    	}
    	const difference = Math.abs(from - to);
    	const scroll_step = Math.ceil(difference / duration * 50);
    
    	function scroll(start, end, step) {
    		if (start === end) {
    			return;
    		}
    
    		let d = (start + step > end) ? end : start + step;
    
    		if (start > end) {
    			d = (start - step < end) ? end : start - step;
    		}
    
    		if (el === window) {
    			window.scrollTo(d, d);
    		} else {
    			el.scrollTop = d;
    		}
    
    		window.requestAnimationFrame(() => scroll(d, end, step));
    	}
    
    	scroll(from, to, scroll_step);
    }
    

    小编不容易点个赞再走把

  • 相关阅读:
    scipy.spatial.distance.cdist
    关于hstack和Svstack
    numpy.hstack(tup)
    numpy.random.uniform(记住文档网址)
    Python集合(set)类型的操作
    python+Eclipse+pydev环境搭建
    python数据挖掘领域工具包
    LVS 命令使用
    CMD mysql 备份脚本
    Windos Server Tomcat 双开配置
  • 原文地址:https://www.cnblogs.com/wangjiahui/p/11978313.html
Copyright © 2011-2022 走看看