Javascript sliding switch between the left and right sides of the width effect

Source: Internet
Author: User
Tip: you can modify some code before running

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>The effect of sliding between the left and right sides of the webpage to switch the width of both sides</title><meta http-equiv="content-type" content="text/html;charset=gb2312"><!--把下面代码加到<head>与</head>之间--><style type="text/css">Html, body {height: 100%; overflow: hidden;} body {margin: 0px; padding: 0px; background: #000 ;}# huakuai {width: 800px; height: 100%; top: 0px; right:-400px; background: # ff0000; position: absolute;} # but {width: 100px; height: 100px; left:-50px; top: 50%; display: inline; margin:-50px 0 0 0; position: absolute; background: # fff; cursor: pointer ;}</style><script type="text/javascript">Window. onload = function () {var oRight = document. getElementById ('huakuai'); var oBut = document. getElementById ('but'); var oPath = true; oBut. onclick = function () {if (oPath) {sMove (oRight, 'right', 0); oPath = false;} else {sMove (oRight, 'right ', -400); oPath = true ;}}; function getStyle (obj, attr) {return obj. currentStyle? Obj. currentStyle [attr]: getComputedStyle (obj, false) [attr];} function sMove (obj, attr, iT) {clearInterval (obj. timer); obj. timer = setInterval (function () {dMove (obj, attr, iT) ;}, 30) ;}function dMove (obj, attr, iT) {var iCur = 0; iCur = parseInt (getStyle (obj, attr); var iS = (iT-iCur)/5; iS = iS> 0? Math. ceil (iS): Math. floor (iS); iCur = iT? ClearInterval (obj. timer): obj. style [attr] = iCur + iS + 'px ';}};</script></head><body><!--把下面代码加到<body>与</body>之间--><div >Content on the left</div><div id="huakuai"> <div id="but">Click here to slide</div><!--可使用箭头进行切换--> <div >Content on the right</div></div></body></html></td> </tr></table>
Tip: you can modify some code before running

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.