/*
*/
$("input").focus(function(even){
var bu =($(document).scrollTop()-this.offsetTop<window.screen.availHeight/2)?-200:200;
window.scrollTo(0,this.offsetTop+bu);
})
/*
*/
$("input").focus(function(even){
var bu =($(document).scrollTop()-this.offsetTop<window.screen.availHeight/2)?-200:200;
window.scrollTo(0,this.offsetTop+bu);
})
"We are champion"判断字符串中最长单词的长度
先上代码
/*
*/
var src="We are champion";
var arr=src.split(" ").map(function(even){retrun even.length});
console.log(Math.max.apply(this , arr))
然后才是废话
对象.map(callback(index,domElement))
对象可以是 数组,或者jq数组,毕竟map()是jq的遍历函数
返回也是jquery数组,因此需要直接调用并输出请
/*
*/
src.split(" ").map(function(even){return even.length}).get().join(',');
//输出结果
2,3,8
对象.apply(this arr)
这个我还没理解……
对象.forEach()
Firefox 和Chrome 的Array 类型都有forEach的函数。使用如下:
/*
*/
arryAll.forEach(function(e){
alert(e);
})
但是IE不支持
因为IE的Array 没有这个方法
所以要做兼容函数
/*
*/
//Array.forEach implementation for IE support..
//https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
var T, k;
if (this == null) {
throw new TypeError(" this is null or not defined");
}
var O = Object(this);
var len = O.length >>> 0; // Hack to convert O.length to a UInt32
if ({}.toString.call(callback) != "[object Function]") {
throw new TypeError(callback + " is not a function");
}
if (thisArg) {
T = thisArg;
}
k = 0;
while (k < len) {
var kValue;
if (k in O) {
kValue = O[k];
callback.call(T, kValue, k, O);
}
k++;
}
};
}
$("button").prop("disabled", true)—— prop操作属性
$("#target2").appendTo("#right-well")——转移元素到目标名下
$("#target2").clone().appendTo("#right-well")——先复制再转移元素到目标名下
$(".target:nth-child(3)").addClass("animated bounce");——选择第几个子元素【:nth-child(3)】
$("a[href='"+ window.location.pathname +"']").parent().attr("class","active");
/**/ 设置或获取对象指定的文件名或路径。 alert(window.location.pathname) 设置或获取整个 URL 为字符串。 alert(window.location.href); 设置或获取与 URL 关联的端口号码。 alert(window.location.port) 设置或获取 URL 的协议部分。 alert(window.location.protocol) 设置或获取 href 属性中在井号“#”后面的分段。 alert(window.location.hash) 设置或获取 location 或 URL 的 hostname 和 port 号码。 alert(window.location.host) 设置或获取 href 属性中跟在问号后面的部分。 alert(window.location.search)
/*
*/
$('input').bind('input propertychange', the_change);
function the_change(){
}
2016-5-17 17:13:35-
在浏览器流畅运行的代码,在微信打开竟然卡到爆炸,十分不流畅
即使已经封装好了
(function() {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || // Webkit中此取消方法的名字变了
window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
var id = window.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
}());
出现该问题的代码,持续找原因ing
/*
*/
$("#start").click(function() {
var start = 0, during = 100;
var _run = function() {
start++;
var the_top = Tween.Quad.easeOut(start, ball.x , -600, during);
$("#ball1").css({"top":the_top});
if(start < during)requestAnimationFrame(_run);
};
_run();
})
/* */ 网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeight 网页可见区域宽: document.body.offsetWidth (包括边线的宽); 网页可见区域高: document.body.offsetHeight (包括边线的宽); 网页正文全文宽: document.body.scrollWidth 网页正文全文高: document.body.scrollHeight 网页被卷去的高: document.body.scrollTop 网页被卷去的左: document.body.scrollLeft 网页正文部分上: window.screenTop 网页正文部分左: window.screenLeft 屏幕分辨率的高: window.screen.height 屏幕分辨率的宽: window.screen.width 屏幕可用工作区高度: window.screen.availHeight 屏幕可用工作区宽度:window.screen.availWidth alert($(window).height()); //浏览器当前窗口可视区域高度 alert($(document).height()); //浏览器当前窗口文档的高度 alert($(document.body).height());//浏览器当前窗口文档body的高度 alert($(document.body).outerHeight(true));//浏览器当前窗口文档body的总高度 包括border padding margin alert($(window).width()); //浏览器当前窗口可视区域宽度 alert($(document).width());//浏览器当前窗口文档对象宽度 alert($(document.body).width());//浏览器当前窗口文档body的高度 alert($(document.body).outerWidth(true));//浏览器当前窗口文档body的总宽度 包括border padding margin?
/* */ typeof(abc) != "undefined"
/*
防吞*/
/*===========================================in_array 小函数*/
function in_array(search,array){
for(var i in array){
if(array[i]==search){
return true;
}
}
return false;
}
/*调用*/
in_array(11,arr)
<head>里面插入两行
/*
一二楼防吞*/
<script src="http://siteapp.baidu.com/static/webappservice/uaredirect.js" type="text/javascript" ></script>
<script type="text/javascript">uaredirect("手机版网址");</script >