Move horizontally-ad map (web)

Source: Internet
Author: User

Project

(Mobile Billboard)

Requirements:

1, the implementation of the picture once in a moving way, to the last full appearance, rebound to the first

2, the mouse on the picture above the picture move, the mouse left, the picture stops moving

HTML structure <! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> Rebound Effects </title>
<link rel= "stylesheet" href= "Css/index.css"/>
<body>

<!--Create an outer box--
<div id= "box" >

<!--a box in the outer box for storing pictures--
<div id= "IMGs" >






</div>

</div>
</body>

<script type= "Text/javascript" src= "Js/index.js" ></script>
CSS Layout


*{
    padding:0;
    margin:0;
}
/* Add background image, personal hobbies */
body{
    background:url (.. /img/quan4.jpg);
}

/* Note To set the margin for the outer box and hide the out-of-section */
#box {
    position:relative;
    margin:10px Auto;
    width:500px;
    height:250px;
    border:5px solid red;
    overflow:hidden;
    /*background-color:chocolate;*/
}

/* The box with the picture is set to absolute positioning; width is the width of all pictures,

This allows the picture to be arranged horizontally, hiding the outside part */
#imgs {
Position:absolute;
margin:10px;
width:2400px;
height:230px;
Overflow:hidden;
}

/* Set a uniform height and width for all pictures, floating to the left, relative positioning */
#imgs img{
position:relative;
Float:left;
width:400px;
height:230px;

}

JS Animation


Use the $ () function
function $ (ID) {
return document.getElementById (ID);
}

When the mouse hovers inside the large box (get focus), open the timer
$ ("box"). onmouseover = function () {
Clearinterval (timer);
Timer = setinterval (runtimes,3);

}

Stop the timer when the mouse leaves inside the large box (loses focus)
$ ("box"). onmouseout = function () {
Clearinterval (timer);
}

var Poit = 10;//Create a variable to receive the target value we want to change
var leader = 0;//Create a variable, set the animation effect
var timer = null;//Timer variable, open and stop timer required


Create a function to change the target value
Function runtimes () {
Poit--;

Set the animation so that the value of leader is 0
Leader = leader + (Poit-leader)/10;

$ ("IMGs"). Style.marginleft = leader + "px";

To achieve a rebound effect (the desired value is set according to the specific situation)

If the last picture is fully displayed, give the initial value to the target value again.
if (Poit <-1900) {
Poit = 10;
}
}

Ideas

1, a large box inside a small box, a small box to put pictures

2, the large box with the height of the small box, the width of the small box for all the picture width of the sum

3, the picture is equal in width, the height of the picture is the same as the small box, and floats to the left

4, set the margin of the small box to the initial value of 0, beyond the partially hidden

5, call the timer to change the margin of the small box, the effect of moving the picture to the left (to a certain value in the re-assigned to the initial value)

Move horizontally-ad map (web)

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.