Js implements transparency gradient, js implements transparency gradient

Source: Internet
Author: User

Js implements transparency gradient, js implements transparency gradient

This document describes how to implement a progressive transparency effect in JavaScript. Share it with you for your reference. The specific analysis is as follows:

Here, the transparency of the element at the beginning is 30. When the mouse moves up, the transparency increases slowly until the transparency is stopped by 100. Move the mouse out, and the transparency decreases slowly to 30.

Key Aspect 1: Because you cannot directly obtain or change the transparency value, you can assign the transparency value to a variable, change the variable, and finally assign the value of the variable to the transparency value of the element.

var alpha=30;

Key Aspect 2: Determine the target value and the current transparency value to determine whether it is a positive speed or a negative speed.

if(target > alpha){speed = 2;}else{speed = -2;}

Key Aspect 3: If the transparency value reaches the target value, turn off the timer; otherwise, the transparency value continues to change. Finally, assign the value to the element. Because the transparency is incompatible, write two statements.

if(alpha == target){clearInterval(timer);}else{alpha = alpha + speed;run.style.filter = 'alpha(opacity='+alpha+')';run.style.opacity = alpha/100;document.title = alpha;}

Finally, run the following code:

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

I hope this article will help you design javascript programs.

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.