JS simulates jquery's slide and Fadein and fadeout features _javascript skills

Source: Internet
Author: User
Tags setinterval
Just think of how jquery is realized, helpless, brother ability is poor, not to study the jquery source. Well, make a very simple version of yourself, hehe! It seems to be OK, waiting for Brother's ability to go up again to optimize the next
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns=" http://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/> <title> three-column layout </title> <style> #main1 {margin:20px auto; width:200px; Background-color: #6c9; Overflow:hidden; } </style> <script type= "Text/javascript" > var Animate = {obj:null, itime:0, Flag:1, MaxHeight: 0, _$: function (ID) {return "string" = typeof (ID)? document.getElementById (ID): ID; }, Slidedown:function () {if (parseint (this.obj.style.height) > this.maxheight) {this.flag = 0; return}; This.obj.style.height = parseint (this.obj.style.height) + 1 + ' px '; SetTimeout ("Animate.slidedown ()", this.itime); }, Slideup:function () {if (parseint (This.obj.style.height) < 1) {This.flag = 1; return}; This.obj.style.height = parseint (this.obj.style.height)-1 + ' px '; var repeat = "animate.slideup ()"; SetTimeout (Repeat,this.itime); }, Slide:function (objid,itime) {this.obj = this._$ (ObjID); This.itime = itime; if (this.flag) {this.maxheight = This.maxheight this.maxheight:p arseint (this.obj.style.height); This.obj.style.display = "block"; This.obj.style.height = "0px"; This.slidedown (); else {this.slideup (); }, Fadein:function (objid,itime) {this.obj = this._$ (ObjID); This.itime = itime; var that = this; This.maxheight =parseint (this.obj.style.height); var i = 100; var timer = setinterval (function () {That.obj.style.cssText = "Filter:alpha" (opacity= "+ i +");-moz-opacity: "+i*0.01+"; op Acity: "+i*0.01+"; Height: "+that.maxheight+" PX; i--; if (i = = 0) clearinterval (timer); },that.itime); }, Fadeout:function (objid,itime) {this.obj = this._$ (ObjID); This.itime = itime; var that = this; This.maxheight =parseint (this.obj.style.height); var i = 0; var timer = setinterval (function () {That.obj. Style.csstext = "Filter:alpha" (opacity= "+ i +");-moz-opacity: "+i*0.01+"; Opacity: "+i*0.01+"; Height: "+that.maxheight + "PX;"; i++; if (i ==100) clearinterval (timer); },that.itime); } </script> </pead> <body> <input type= "button" value= "Slide" onclick= "animate.slide (' main1 ', 1 0) "/> <input type=" button "value=" FadeIn "onclick=" Animate.fadein (' main1 ', ten) "/> <input type=" button "Val Ue= "fadeout" onclick= "animate.fadeout (' main1 ', ten)"/> <div id= "main1" > Slide && fadeIn && fade In && fadeout </div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

After running, everyone looks at the effect.

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.