First, take a look at the running effect as shown in the figure below.
Move the mouse over a star and all the stars in front of the star will light up. Clicking the mouse will record the number of stars clicked and all the stars in front will light up.
1. Principle
The principle of this program is as follows: a "ul" label, the background of the label is gray stars, control the width of the "ul" label to display the number of stars. For example: if the width of a star picture is 23px, then if you want to display 10 stars, then the width of "ul" is 230px to display 10 stars.
n "li" tags, n represents the number of stars you want to display. For example, if you want to display 10 stars, there will be 10 "li" tags. Then the width of these 10 labels is 23px for 1 star, 46px for 2 stars,..., 230px for 10 stars. The background of these "li" tags will be blue stars.
There is also a "li" tag to record the stars or initial settings clicked by the mouse.
These labels are all overlapped. Use the mouse sliding effect to switch the stacking order of these labels to display different numbers of stars. Click to record the number of stars.
2. Source code
$.fn.studyplay_star=function(options,callback){
//Default settings
var settings ={
MaxStar :20,
StarWidth :23,
CurrentStar :5,
Enabled :true
};
if(options) { jQuery.extend(settings, options); };
var container = jQuery(this);
container.css({"position" :"relative"})
.html('
.find('.studyplay_starBg').width(settings.MaxStar*settings. StarWidth)
.html('
if(settings.Enabled)
{
var ListArray = "";
for(k=1;k
ListArray ='
}
container.find('.studyplay_starBg').append(ListArray)
.find('.studyplay_starON').hover(function(){
$("#studyplay_current" ).hide();
$(this).removeClass('studyplay_starON').addClass("studyplay_starovering");
},
function(){
$(this).removeClass( 'studyplay_starovering').addClass("studyplay_starON");
$("#studyplay_current").show();
})
.click(function(){
var studyplay_count = settings. MaxStar - $(this).css("z-index") 1;
$("#studyplay_current").width(studyplay_count*settings.StarWidth)
//Callback function
if (typeof callback == 'function') {
callback(studyplay_count);
return ;
}
})
}
}
This plugin has two The first parameter is options, which represents some basic settings of the plug-in; callback represents the callback function, which has a parameter indicating the number of stars selected by the user.
3. Use
If we want to display 5 stars on the div with the id "z", one star will be selected by default, and a dialog box for selecting the number of stars will pop up, as follows: Write code:
If you want to display the rating results, you can Set Enabled to false and it will be ok
4. Code download
Netizens reported that this problem exists in Firefox. Today, we debugged and modified it. The main reason is that the height of the li tag in the style is not defined. Now It has been corrected, thank you friends. Firefox revised version download address:
star2.rar
Sincerely thank you netizens
The third modification: add a 0.5-point scoring function
Instructions for use: half equals 0. Increasing by one point, 1 means an increase of 0.5
For example: $("#z").studyplay_star({MaxStar:12,CurrentStar:2,Enabled:true,Half:1},function(value){ alert(value)});
Download address: halfstar2.rar

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.

I built a functional multi-tenant SaaS application (an EdTech app) with your everyday tech tool and you can do the same. First, what’s a multi-tenant SaaS application? Multi-tenant SaaS applications let you serve multiple customers from a sing

This article demonstrates frontend integration with a backend secured by Permit, building a functional EdTech SaaS application using Next.js. The frontend fetches user permissions to control UI visibility and ensures API requests adhere to role-base


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft