// 监听滚动,用于列表页向下加载---------------------------------
function loadmore(callback) {
$(window).scroll(function () {
var scrollTop = $(this).scrollTop(); //滚动条距离顶部的高度
var scrollHeight = $(document).height(); //当前页面的总高度
var clientHeight = $(this).height(); //当前可视的页面高度
//距离顶部+当前高度 >=文档总高度 即代表滑动到底部
if (scrollTop + clientHeight >= scrollHeight - 200) {
callback && callback()
}
});
}
// toast弱提示 提示框--------------------------------------
function toast(config) {
var mask = document.getElementById("toast_mask");
var func = config.func;
if (!mask) {
mask = document.createElement("div");
mask.id = "toast_mask";
mask.className = "toast_mask f26"; mask.innerHTML = '<div class="toast_box" id="toast_box">' +
'<div class="tips_content" id="toast_info">' + config.msg + '</div>' +
'</div>';
document.body.appendChild(mask);
} else {
mask.style.display = "flex";
}
//延时消失
setTimeout(() => {
mask.style.display = "none";
func && func();
}, config.duration || 3000)
//点击时消失
mask.onclick = () => {
mask.style.display = "none"
}
document.getElementById("toast_info").innerText = config.msg;
}
//过滤数组重复项---------------------------------------------------------------
let getNo_list = () => {
var arr = [1, 2, 3, 1, 3, 4, 5, 5];
var resultArr = [];
for (i = 0; i < arr.length; i++) {
for (j = 0; j < resultArr.length; j++) {
if (resultArr[j] == arr[i]) {
break;
}
}
if (j == resultArr.length) {
resultArr[resultArr.length] = arr[i];
}
}
console.log(resultArr); //1,2,3,4,5
}
//数组排序 从小到大---------------------------------------------------------
let list_isBig = (arr) => {
for (var j = 0; j < arr.length - 1; j++) {
//两两比较,如果前一个比后一个大,则交换位置。
for (var i = 0; i < arr.length - 1 - j; i++) {
if (arr[i] > arr[i + 1]) {
var temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
}
return arr
}
//获取json长度----------------------------------------------------------
let getJsonObjLength = (jsonObj) => {
var Length = 0;
for (var item in jsonObj) {
Length++;
}
return Length;
}
//传入一个开始时间('2019','1')返回一个时间戳区间
let computeTime = (year, month) => {
return [
// new Date(year, month - 1, 1).getTime(),
// new Date(year, month, 0).getTime() + (24 * 60 * 60 * 1000 - 1000) 注释的和非注释都可用
new Date(year, month - 1, 1).getTime() / 1000,
new Date(year, month, 1).getTime() / 1000 - 1
]
}
//传入时间戳,第二个参数是格式,也可不传
let parseTime = (time, pattern) => {
if (!time) {
return null
}
const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
let date
if (typeof time === 'object') {
date = time
} else {
if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
time = parseInt(time)
}
if ((typeof time === 'number') && (time.toString().length === 10)) {
time = time * 1000
}
date = new Date(time)
}
const formatObj = {
y: date.getFullYear(),
m: date.getMonth() + 1,
d: date.getDate(),
h: date.getHours(),
i: date.getMinutes(),
s: date.getSeconds(),
a: date.getDay()
}
const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
let value = formatObj[key]
// Note: getDay() returns 0 on Sunday
if (key === 'a') {
return ['日', '一', '二', '三', '四', '五', '六'][value]
}
if (result.length > 0 && value < 10) {
value = '0' + value
}
return value || 0
})
return time_str
}
// 复制
function copy(item) {
if (isIosorAn() == "ios") {
is_iosCopy(item)
} else {
var text = document.createElement("input");
text.id = "sharecopy";
text.value = item;
text.style.position = "fixed";
text.style.top = "-10000px";
text.readOnly = false;
document.body.appendChild(text);
text.select();
var copys = document.execCommand("copy");
text.blur();
text.remove();
if (copys) {
toast({
msg: "复制成功"
})
} else {
toast({
msg: "复制失败"
})
}
}
} function is_iosCopy(item) {
var el = document.createElement('input');
el.value = item
el.style.opacity = '0';
document.body.prepend(el);
el.type = "text"
var editable = el.contentEditable;
var readOnly = el.readOnly;
el.contentEditable = true;
el.readOnly = false;
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
el.setSelectionRange(0, 999999);
el.contentEditable = editable;
el.readOnly = readOnly;
var ret = document.execCommand('copy');
el.blur();
el.remove()
if (ret) {
toast({
msg: "复制成功"
})
} else {
toast({
msg: "复制失败"
})
}
} function isIosorAn() {
var equipmentType = "";
var agent = navigator.userAgent.toLowerCase();
var android = agent.indexOf("android");
var iphone = agent.indexOf("iphone");
var ipad = agent.indexOf("ipad");
if (android != -1) {
equipmentType = "android";
}
if (iphone != -1 || ipad != -1) {
equipmentType = "ios";
}
return equipmentType;
}

js常用 方法 封装的更多相关文章

  1. 自动化测试中执行JS脚本方法封装

    执行JS脚本方法封装: class JavaScript(Base): def execute_javascript(self, js): """执行 JavaScrip ...

  2. js常用的封装函数

    1.使用childNodes获取元素的元素节点 //使用childNodes获取元素节点 function cNodes(obj){ var arr=new Array(); for(var i=0; ...

  3. 常用js方法封装

    常用js方法封装 var myJs = { /* * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值是格式化的字符串日期 */ getDates: fun ...

  4. 第60天:js常用访问CSS属性的方法

    一. js 常用访问CSS 属性的方法 我们访问得到css 属性,比较常用的有两种: 1. 利用点语法  box.style.width      box.style.top     点语法可以得到 ...

  5. js实现第一次打开网页弹出指定窗口(常用功能封装很好用)

    js实现第一次打开网页弹出指定窗口(常用功能封装很好用) 一.总结 1.常用功能封装:之前封装的cookie的操作函数非常好用,我自己也可以这么搞 二.js实现第一次打开网页弹出指定窗口 练习1:第一 ...

  6. C#常用字符串加解密方法封装

    C#中常用的字符串加密.解密方法封装,包含只加密但不解密的方法.收藏起来备用. //方法一 //须添加对System.Web的引用 //using System.Web.Security; /// & ...

  7. 【转】第7篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:全自动注册与反射方法分析

    作者: 牛A与牛C之间 时间: 2013-12-12 分类: 技术文章 | 2条评论 | 编辑文章 主页 » 技术文章 » 第7篇:Xilium CefGlue 关于 CLR Object 与 JS ...

  8. 【转】第6篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+自动反射方法分析

    作者: 牛A与牛C之间 时间: 2013-11-21 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第6篇:Xilium CefGlue 关于 CLR Object 与 JS ...

  9. 【转】第5篇:Xilium CefGlue 关于 CLR Object 与 JS 交互类库封装报告:自动注册JS脚本+委托回调方法分析

    作者: 牛A与牛C之间 时间: 2013-11-19 分类: 技术文章 | 暂无评论 | 编辑文章 主页 » 技术文章 » 第5篇:Xilium CefGlue 关于 CLR Object 与 JS ...

随机推荐

  1. Spring IOC 之注册解析的 BeanDefinition

    2019独角兽企业重金招聘Python工程师标准>>> DefaultBeanDefinitionDocumentReader.processBeanDefinition() 完成 ...

  2. JAVA编程思想 Ch3.5题

    练习5:创建一个class类,包含连两个String字段 :name.says.在main方法中创建两个Dog方法 一个命名为spot 叫声为 Ruff,另一个命民为scruffy,叫声为:Wuff: ...

  3. MySQL分页查询的性能优化

    MySQL limit分页查询的性能优化 Mysql的分页查询十分简单,但是当数据量大的时候一般的分页就吃不消了. 传统分页查询:SELECT c1,c2,cn… FROM table LIMIT n ...

  4. CF思维联系– Codeforces-990C Bracket Sequences Concatenation Problem(括号匹配+模拟)

    ACM思维题训练集合 A bracket sequence is a string containing only characters "(" and ")" ...

  5. HDU 1159.Common Subsequence【动态规划DP】

    Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...

  6. 数学--数论--HDU - 6322 打表找规律

    In number theory, Euler's totient function φ(n) counts the positive integers up to a given integer n ...

  7. [bzoj2427]P2515 [HAOI2010]软件安装(树上背包)

    tarjan+树上背包 题目描述 现在我们的手头有 \(N\) 个软件,对于一个软件 \(i\),它要占用 \(W_i\) 的磁盘空间,它的价值为 \(V_i\).我们希望从中选择一些软件安装到一台磁 ...

  8. Jenkins 构建 Jmeter 项目之源代码管理(SVN)

    1.查看项目创建中是否又 svn 插件,没有的话下载插件 subversion 2.配置 svn 源代码管理,如下图(testcases 目录下包含 build.xml 和脚本文件) 3.查看 Jen ...

  9. Northwestern European Regional Contest 2014 Gym - 101482

    Gym 101482C Cent Savings 简单的dp #include<bits/stdc++.h> #define inf 0x3f3f3f3f #define inf64 0x ...

  10. R - Weak Pair HDU - 5877 离散化+权值线段树+dfs序 区间种类数

    R - Weak Pair HDU - 5877 离散化+权值线段树 这个题目的初步想法,首先用dfs序建一颗树,然后判断对于每一个节点进行遍历,判断他的子节点和他相乘是不是小于等于k, 这么暴力的算 ...