Some of the simple jquery plugins that you've encapsulated

Source: Internet
Author: User

As the saying goes: warm so know new, can for division!

Learning is a lifelong thing for a Person. So take advantage of Today's rest, review Some knowledge points, may do not perfect, please advise.

/**
* Created by Administrator on 2017/5/6.
*/

/**
* Formatted date
* @param dt Date Object
* @returns {string} return value is a formatted string date
*/
function GetDates (dt) {
var str = "";//string that stores time
Get year
var year = Dt.getfullyear ();
Get month
var month = Dt.getmonth () + 1;
Get Day
var day = Dt.getdate ();
Get hours
var hour = dt.gethours ();
Get minutes
var min = dt.getminutes ();
Get seconds
var sec = Dt.getseconds ();
Month = Month < 10? "0" + month:month;
Day = Day < 10? "0" + day:day;
Hour = Hour < 10? "0" + hour:hour;
min = min < 10? "0" + min:min;
SEC = sec < 10? "0" + sec:sec;
str = year + "years" + month + "month" + day + "days" + hour + ":" + min + ":" + sec;
Return str;
}
/**
* Gets the specified Label object
* id attribute value for @param ID tag
* @returns {Element} Returns the specified Label object based on the value of the id attribute
*/
function my$ (id) {
return document.getElementById (id);
}
/**
* Set the text content of the element
* Elements @param element
* @param text content
*/
function Setinnertext (element, Text) {
If (typeof (element.textcontent) = = "undefined") {
Element.innertext = text;
} else {
Element.textcontent = text;
}
}
/**
* Gets the text content of the element
* Elements @param element
* @returns The text contents of any element in {*}
*/
function Getinnertext (element) {
If (typeof (element.textcontent) = = "undefined") {
Return element.innertext;
} else {
Return element.textcontent;
}
}
/**
* Gets the first child element in a parent element
* @param element Parent elements
* @returns a child element in the parent element of {*}
*/
function Getfirstelement (element) {
If (element.firstelementchild) {
Return element.firstelementchild;
} else {
var node = element.firstchild;
While (node && node.nodetype! = 1) {
node = node.nextsibling;
}
Return node;
}
}
/**
* Gets the last child element in the parent element
* @param element Parent elements
* @returns {*} Last child element
*/
function Getlastelement (element) {
If (element.lastelementchild) {
Return element.lastelementchild;
} else {
var node = element.lastchild;
While (node && node.nodetype! = 1) {
node = node.previoussibling;
}
Return node;
}
}
/**
* Gets the previous sibling element of an element
* Elements @param element
* @returns {*} before a sibling element
*/
function Getpreviouselement (element) {
If (element.previouselementsibling) {
Return element.previouselementsibling
} else {
var node = element.previoussibling;
While (node && node.nodetype! = 1) {
node = node.previoussibling;
}
Return node;
}
}
/**
* Gets the next sibling element of an element
* Elements @param element
* @returns {*} after a sibling element
*/
function Getnextelement (element) {
If (element.nextelementsibling) {
Return element.nextelementsibling
} else {
var node = element.nextsibling;
While (node && node.nodetype! = 1) {
node = node.nextsibling;
}
Return node;
}
}
/**
* Get all sibling elements of an element
* Elements @param element
* @returns {Array} Sibling element
*/
function Getsiblings (element) {
If (!element) return;
var elements = [];
var ele = element.previoussibling;
While (ele) {
if (ele.nodetype = = = 1) {
Elements.push (ele);
}
Ele = ele.previoussibling;
}
Ele = element.nextsibling;
While (ele) {
if (ele.nodetype = = = 1) {
Elements.push (ele);

}
Ele = ele.nextsibling;
}
Return elements;
}
/**
* Returns what type of browser the current browser is
*/
function Userbrowser () {
var browsername=navigator.useragent.tolowercase ();
If (/msie/i.test (browsername) &&!/opera/.test (browsername)) {
Console.log ("IE");
}else if (/firefox/i.test (browsername)) {
Console.log ("Firefox");
}else if (/chrome/i.test (browsername) &&/webkit/i.test (browsername) &&/mozilla/i.test (browsername) ){
Console.log ("Chrome");
}else if (/opera/i.test (browsername)) {
Console.log ("Opera");
}else if (/webkit/i.test (browsername) &&! ( /chrome/i.test (browsername) &&/webkit/i.test (browsername) &&/mozilla/i.test (browsername))) {
Console.log ("Safari");
}else{
Console.log ("don't know what the hell!");
}
}

function GetStyle (element,attr) {
return Element.currentstyle?element.currentstyle[attr]:window.getcomputedstyle (element,null) [attr];
}
Encapsulation of an easing animation function
Function Animate (element, Json,fn) {
Clearinterval (element.timeid);
Element.timeid = SetInterval (function () {
var flag=true;
For (var attr in Json) {
If (attr== "opacity") {
var current = GetStyle (element, attr) *100;
var target=json[attr]*100;
Number of steps per move
var step = (target-current)/10;
Each move step is an integer (larger number)
Step = step > 0? Math.ceil (step): Math.floor (step);
Current + = Step;//the pixel after the move
element.style[attr] = current/100;
}else if (attr== "zIndex") {
element.style[attr]=json[attr];
}else{
var current = parseint (getStyle (element, attr));
var target=json[attr];
Number of steps per move
var step = (target-current)/10;
Each move step is an integer (larger number)
Step = step > 0? Math.ceil (step): Math.floor (step);
Current + = Step;//the pixel after the move
element.style[attr] = current + "px";
}
If (current! = Target) {//stop timer after reaching target
flag=false;
}
}
If (flag) {
Clearinterval (element.timeid);//cleanup Timer
If (fn) {
FN ();
}
}
Console.log ("target:" + target + ", current:" + current + ", step:" + step ");
}, 20);
}


//code for the tool for the event argument object
var evttools={
//event parameter
evt:function (e) {
return window.event?window.event:e ;
},
//page to the left curl the distance
left:function () {
return window.pagexoffset| | document.body.scrollleft| | document.documentelement.scrollleft| | 0;
},
//page to curl up the distance
top:function () {
return window.pageyoffset| | document.body.scrolltop| | document.documentelement.scrolltop| | 0;   
}, the properties in the
//event argument object encapsulate the horizontal axis of the visible area---
clientx:function (e) {
return this.evt (e). clientX;
  }, the properties in the
///event parameter object encapsulate the ordinate of the visible area of the---
clienty:function (e) {
return this.evt (e). clientY;
  },
pagex:function (e) {
return this.evt (e). pagex?this.evt (e). pageX:this.left () +this.clientx (e);
  },
pagey:function (e) {
return this.evt (e). pagey?this.evt (e). pageY:this.top () +this.clienty (e);
}
};

When the width of the browser changes, get the browser (the width of the viewable area of the Page)
function Getclient () {
return{
width:window.innerwidth| | document.body.clientwidth| | document.documentelement.clientwidth| | 0,
height:window.innerheight| | document.body.clientheight| | document.documentelement.clientheight| | 0
}
}

Some of the simple jquery plugins that you've encapsulated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.