JavaScript implementation of the Click button to allow the div layer to move in a flexible way _javascript skills

Source: Internet
Author: User

This article illustrates how JavaScript implements the Click button to move the div layer flexibly. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Click button to let div layer flex move effect </title>
<style type= "Text/css" >
#div1 {background: #FFCC66; border: #FF6600 1px solid; height:100px; width:100px; position:relative; left:0px;}
</style>
<script type= "Text/javascript" >
var t=null;
function Startmove ()
{
if (t)
{
Clearinterval (t);
}
T=setinterval (move, 30);
}
var step=0;
function Move ()
{
var Odiv=document.getelementbyid ("Div1");
step+= (100-odiv.offsetleft)/50;
step=step*0.98
Odiv.style.left=odiv.offsetleft+step;
}
</script>
<body>
<div id= "Div1" >
</div>
<input type= "button" value= "mobile" onclick= "Startmove ()"/>
</body>

I hope this article will help you with your JavaScript programming.

Related Article

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.