HTML + JavaScript implement chain motion effects, javascript chain

Source: Internet
Author: User

HTML + JavaScript implement chain motion effects, javascript chain

In the process of learning js, I found this guy is really good at doing special effects. Although the current level is not enough, it can also write some simple results. Today, I will share a simple motion frame and use it to implement simple chain motion effects.

1. move. js

In the motion frame, the length and width changes and the transparency changes. The variation of length and width can achieve the effect of DIV volume movement change. Transparency is mainly used to add the effect of fade in and out in the move-in event. I encapsulated this simple motion framework into a separate js file for convenient calling.

First look at the Code:

<Span style = "font-family: KaiTi_GB2312;"> // used to obtain a non-interline style </span> function getStyle (obj, name) {if (obj. currentStyle) {return obj. currentStyle [name];} else {return getComputedStyle (obj, false) [name] ;}< span style = "font-family: KaiTi_GB2312; "> // The four parameters are respectively object, attribute, modification value, function </span> function startMove (obj, attr, iTarget, func) {clearInterval (obj. timer); obj. timer = setInterval (function () {var cur = 0; <span style = "font-family: KaiTi_GB2312; "> // Determine whether the property to be changed is transparent </span> if (attr = 'opacity ') {cur = parseFloat (getStyle (obj, attr) * 100);} else {cur = parseInt (getStyle (obj, attr);} // <span style = "font-family: KaiTi_GB2312; "> motion speed calculation </span> var speed = (iTarget-cur)/6; speed = speed> 0? Math. ceil (speed): Math. floor (speed); if (cur = iTarget) {clearInterval (obj. timer); <span style = "font-family: KaiTi_GB2312;"> // If function parameters exist, then the execution function </span> if (f <span style = "font-family: KaiTi_GB2312;"> unc </span>) {<span style = "font-family: kaiTi_GB2312; "> </span> f <span style =" font-family: KaiTi_GB2312; "> unc </span> ();}} else {if (attr = 'opacity ') {<span style = "font-family: KaiTi_GB2312; "> // ensure compatibility between IE and FF </span> <span style =" font-family: KaiTi_GB2312; "> </span> obj. style. filter = 'Alpha (opacity: '+ (cur + speed) +') '; obj. style. opacity = (cur + speed)/100;} else {obj. style [attr] = cur + speed + 'px ';}}, 30 );}

2.index.html

In mouseover: first, change the width of the DIV and wait until the motion ends. Then, the height is changed, and the opacity is changed.

In mouseout: The opacity changes first, the height changes, and the width changes. That is, the movement order of the migration event is the opposite. (This instance has no direct application significance, but some common special effects can be made after the motion frame is improved)

The use of startMove () is similar to recursive call, but it is much easier to understand.

3. Summary

Although the motion framework only has dozens of lines of code, there are still a lot of details. If you use this framework, you should sort out the logic of the code before using it. Otherwise, a bug is enough. Fortunately, I wrote the annotations clearly, hoping to help people who need them.

The previous two motion pictures:

(Ignore watermark)

The specific exercise process should be practiced by yourself. If you make some modifications, the effect will certainly be doubled.


How can I create provincial/municipal joint special effects using javascript and html?

1. Two drop-down box controls
2. Add the corresponding code to the change event of the control in the first drop-down box to change the value of the second control.

Use JAVASCRIPT to implement HTML pages

Hi, let's check if this is not the case:

<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Title> untitled document </title>
</Head>

<Body> <center>
<H3> page title <Hr width = "80%"/>
<Form name = "form1" method = "post" action = "">
<Table width = "509" border = "1" cellspacing = "0" cellpadding = "0">
<Caption>
Header
</Caption>
<Tr>
<Td width = "171" align = "center"> name </td>
<Td colspan = "2" align = "center"> Contact Information </td>
</Tr>
<Tr>
<Td align = "center"> <label>
<Input type = "text" name = "textfield">
</Label> </td>
<Td width = "85" align = "right"> landline </td>
<Td width = "245"> <input type = "text" name = "textfield2"> </td>
</Tr>
<Tr>
<Td align = "center"> </td>
<Td align = "right"> mobile phone </td>
<Td> <input type = "text" name = "textfield3"> </td>
</Tr>
</Table>
</Form>
</Center> </body>
</Html>... the remaining full text>

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.