The sharing side bar animation instance _javascript skill of JS motion frame

Source: Internet
Author: User
Tags setinterval

This paper illustrates the method of sharing side bar animation of JS motion frame. Share to everyone for your reference. The implementation methods are as follows:

Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title></title>
<style type= "Text/css" >
*{
margin:0px;
padding:0px;
}
#div1 {
width:319px;
height:340px;
border:1px solid #FFF;
Position:absolute;
top:100px;
left:-320px;
Background-image:url (images/1.png);
Background-repeat:no-repeat;
}
#div1 span{
width:30px;
height:130px;
BORDER:1PX solid blue;
Position:absolute;
right:-23px;
top:95px;
background:red;
font-family: "Microsoft Ya Hei";
Color: #FFFFFF;
Text-align:center;
line-height:40px;
border-radius:0px 200px 200px 0px;
}
</style>
<script type= "Text/javascript" >
Window.onload=function () {
var Odiv=document.getelementbyid ("Div1");
var ospan=odiv.getelementsbytagname (' span ') [0];
var time=null;
var speed=8;
Odiv.onmouseover=function () {///Here is an event to move the entire Div mouse
Clearinterval (time);
Time=setinterval (function () {
if (odiv.offsetleft>=0) {clearinterval (time);}
else{
odiv.style.left=odiv.offsetleft+speed+ ' px ';
}
},1);
}
Odiv.onmouseout=function () {//here gives the entire div the mouse to move the event
Clearinterval (time);
Time=setinterval (function () {
if (odiv.offsetleft<=-320) {clearinterval (time);}
else{
odiv.style.left=odiv.offsetleft-speed+ ' px ';
}
},1);
}
}
</script>
<body>
<div id= "Div1" >
<span> Share to </span>
</div>
</body>

Optimized code:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<title></title>
<style type= "Text/css" >
*{
margin:0px;
padding:0px;
}
#div1 {
width:319px;
height:340px;
border:1px solid #FFF;
Position:absolute;
top:100px;
left:-320px;
Background-image:url (images/1.png);
Background-repeat:no-repeat;
}
#div1 span{
width:30px;
height:130px;
BORDER:1PX solid blue;
Position:absolute;
right:-23px;
top:95px;
background:red;
font-family: "Microsoft Ya Hei";
Color: #FFFFFF;
Text-align:center;
line-height:40px;
border-radius:0px 200px 200px 0px;
}
</style>
<script type= "Text/javascript" >
Window.onload=function () {
var Odiv=document.getelementbyid ("Div1");
var ospan=odiv.getelementsbytagname (' span ') [0];
var time=null;
var spe=8;
var speed=null;
function Move (bord) {
Clearinterval (time);
Time=setinterval (function () {
if (Odiv.offsetleft>bord) {Speed=-spe;}
Else{speed=spe;}
if (Odiv.offsetleft==bord) {clearinterval (time);}
else{
odiv.style.left=odiv.offsetleft+speed+ ' px ';
}
},1);
}
Odiv.onmouseover=function () {///Here is an event to move the entire Div mouse
Move (0);
}
Odiv.onmouseout=function () {//here gives the entire div the mouse to move the event
Move (-320);
}
}
</script>
<body>
<div id= "Div1" >
<span> Share to </span>
</div>
</body>

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

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.