Web page constant Dynamic effect--rating

Source: Internet
Author: User

Use the variable score record click Index, when the mouse left with score instead of index to complete the effect

Html:

        <Divclass= "box">            <ul>                <binclass= "Current"></Li>                <Li></Li>                <Li></Li>                <Li></Li>                <Li></Li>            </ul>            <P>Comments are divided into<span></span></P>        </Div>

Css:

1 . Box{2 width:150px;3 margin:100px Auto;4}5 . Box Li{6 width:27px;7 Height:28px;8 background:URL (images/star.gif) 0 0 no-repeat;9 float: Left;Ten Margin-right:3px; One} A . Box Li.current{ - background-position:0 Bottom; -}

JQ:

1JQuery (document). Ready (function($) {2                 varScore = 0;//Initialize variables to store fractions3$ ('. Box Li '). Click (function(){4                     varIndex = $ ( This). index ();5$ (". Box Li:lt (" + (index+1) + ")"). AddClass (' current ');6$ (". Box Li:gt (" + (Index) + ")"). Removeclass (' current ');7                     //score = index after completion;8Score =index;9$ (' span '). HTML (index+1);Ten                 }); One$ ('. Box Li '). Hover (function() { A                     varIndex = $ ( This). index (); -$ (". Box Li:lt (" + (index+1) + ")"). AddClass (' current '); -$ (". Box Li:gt (" + (Index) + ")"). Removeclass (' current '); the},function() { -$ (". Box Li:lt (" + (score+1) + ")"). AddClass (' current '); -$ (". Box Li:gt (" + (Score) + ")"). Removeclass (' current '); -                 }); +});

Web page constant Dynamic effect--rating

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.