1. Preface
This scheme is inspired by the JS single-line write a rating component, and wrote a simple demo.
The function has normal sliding, dynamic display the number of solid stars, when the click to confirm, the current number of solid stars, and then when the move is clicked, leave the previous state.
This demo does not have text messages and other prompts, can be added to use as needed.
2. Code
<! DOCTYPE Html>Star height is 21pxif (i <= 5 & i > 0&& pos.y < Offsettopval + + && pos.y > Offsettopval {obj.innerhtml= "★★★★★☆☆☆☆☆". Slice (5-i,10-i);//console.log ("Mousepage (x, y) = (" +pos.x+ "," +pos.y+ ") starnumber=" + Math.floor ((pos.x+6)/13.2));
$ (obj). Click (function () {laststarnum = i;})}} $ (' * '). MouseMove (function () {mOver ();}); function GetPos (EV) {var scrolltop=document.documentelement.scrolltop| | Document.body.scrollTop; var scrollleft=document.documentelement.scrollleft| | Document.body.scrollLeft; return {x:ev.clientx+scrollleft, y:ev.clienty+scrolltop}; }</script>3. Summary
The highlight is the use of the "★★★★★☆☆☆☆☆" Slice (5-laststarnum,10-laststarnum), which does not require an online star rating system that is 5 li elements.
JS Achieve star rating effect (shortest code)