博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javascript DOM编程艺术书中的一些工具函数
阅读量:5152 次
发布时间:2019-06-13

本文共 3524 字,大约阅读时间需要 11 分钟。

function moveElement(elementID,final_x,final_y,interval){

if(!document.getElementById) return false;
if(!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if(elem.movement){
clearTimeout(elem.movement);
}
var xpos = parseInt(elem.offsetLeft);
var ypos = parseInt(elem.offsetTop);
if(xpos == final_x && ypos == final_y){
return true;
}
if(xpos<final_x){
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if(xpos>final_x){
var dist = Math.ceil((xpos - final_x)/10);
}
if(ypos<final_y){
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if(ypos>final_y){
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}

function prepareSlideshow(){  if(!document.getElementsByTagName) return false;    if(!document.getElementById) return false;    if(!document.getElementById("intro")) return false;    var intro = document.getElementById("intro");    var slideshow = document.createrElement("div");    slideshow.setAttribute("id","slideshow");    var frame = document.createElement("img");    frame.setAttribute("src","images/frame.gif");    frame.setAttribute("alt","");    frame.setAttribute("id","frame");    slideshow.appendChild(frame);    var preview = document.createElement("img");    preview.setAttribute("src","images/slideshow.gif");    preview.setAttribute("alt","a glimpse of what awaits you");    preview.setAttribute("id","preview");    slideshow.appendChild(preview);    insertAfter(slideshow,intro);    var links = document.getElementsByTagName("a");    var destination;    for(var i=0; i
//表格隔行变色function stripetables(){  if(!document.getElementsByTagName) return false;    var tables = document.getElementsByTagName("table");    for(var i=0; i

 

 

 

//为不支持placeholder的浏览器添加这个功能function resetfields(whichform){  if(Modernizr.input.placeholder) return ;    for(var i=0; i

 

//ajaxfunction getHTTPObject(){  if(typeof XMLHttpRequest == "undefined"){      XMLHttpRequest = function(){          try{
return new ActiveXObject("Msxml2.XMLHTTP.6.0");} catch(e){} try{
return new ActiveXObject("Msxml2.XMLHTTP.3.0");} catch(e){} try{
return new ActiveXObject("Msxml2.XMLHTTP");} catch(e){} return false; } } return new XMLHttpRequest();}function displayAjaxLoading(element){ while(element.hasChildNodes()){ element.removeChild(element.lastChild); } var content = document.createElement("img"); content.setAttribute("src","images/loading.gif"); content.setAttribute("alt","Loading..."); element.appendChild(content);}function submitFormWidthAjax(whichform,thetarget){ var request = getHTTPObject(); if(!request){
return false;} displayAjaxLoading(thetarget); var dataParts = []; var element; for(var i=0; i
([\s\S]+)<\/article>/); if(matches.length>0){ thetarget.innerHTML = matches[1]; }else{ thetarget.innerHTML = '

Oops,there was an error. Sorry.

'; } }else{ thetarget.innerHTML = '

' + request.statusText + '

'; } } }; request.send(data); return true;}function prepareForms(){ for(var i=0; i

 

转载于:https://www.cnblogs.com/jingangel/archive/2013/01/03/2843505.html

你可能感兴趣的文章
阅读好书依然是提升自己的高效方法:兼以作者的身份告诉大家如何选择书,以及高效学习的方法...
查看>>
浅谈二分图的最大匹配和二分图的KM算法
查看>>
[总结] 单调队列优化多重背包学习笔记
查看>>
js实现弹出的提示框只弹出一次
查看>>
中大阿里巴巴校招笔试个人分享
查看>>
【复习笔记】软件工程概论复习(2)
查看>>
prism4.0——chapter1: 简介
查看>>
c#: 简单的日志管理类(TextWriterTraceListener)
查看>>
三角形面积
查看>>
修改Linux SSH的端口,查看日志
查看>>
Ag (the_silver_searcher) 安装使用
查看>>
[0007] windows 下 eclipse 开发 hdfs程序样例
查看>>
UVA 1368 DNA
查看>>
win7有些电脑form布局发生变化
查看>>
[JLOI 2011]飞行路线&[USACO 09FEB]Revamping Trails
查看>>
bootstrap学习: 基本组件以及布局;
查看>>
UVA 11475 Extend to Palindrome(后缀数组+ST表)
查看>>
伪类选择器:first-child和:nth-child()和:first-of-type
查看>>
安卓生命周期
查看>>
MVC架构之二
查看>>