w

간단 별점 만들기

· 2020-11-06 (금) 11:50:23 · 7886 · 13

작업 중에 제이쿼리와 폰트어썸을 이용해서 간단 별점 평가 적용을 만들어 보았습니다.

워낙 간단한 소스라 팁으로 필요하신 분들 계실까 해서 공유해 봅니다.

 

출력할때에는 아래처럼 출력하시면 됩니다.

<script>

// 아이디, 적용된 평점, true이면 평가가능, false이면 읽기 전용, 폰트크기, 색상
var star = get_star('id1',0,true,24,'#e83e8c');
document.write(star[0]); //css
document.write(star[1]); //별
</script>

 

적용예 => http://shop.wwiz.kr/mshop/itemuselist.php

소스 => http://shop.wwiz.kr/star.php <= 소스보기 하시면 됩니다.

js => http://shop.wwiz.kr/js/star.js <= 다운받아 쓰시면 됩니다.

우선은 색상과 크기만을 지정할 수 있도록 했습니다.

 

 

|

댓글 13개

2020-11-06 (금) 15:55:03
아래 소스 그대로 board 게시판에 넣으면 되는건가요?

<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=0,maximum-scale=10,user-scalable=yes">
<meta name="author" content="">
<meta name="description" content="">
<meta name="keywords" content="">
<meta property="og:type" content="website">
<meta property="og:title" content="MSHOP">
<meta property="og:description" content="">
<meta property="og:url" content="http://shop.wwiz.kr">
<meta property="og:image" content="http://shop.wwiz.kr/data/common/og.image.jpg" />
<title>MSHOP</title>
<link rel="home" href="http://shop.wwiz.kr">
<link rel="shortcut icon" href="http://shop.wwiz.kr/data/common/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="http://shop.wwiz.kr/theme/basic/css/default.css?ver=191202">
<link rel="stylesheet" href="http://shop.wwiz.kr/js/font-awesome/css/font-awesome.min.css?ver=191202">
<link rel="stylesheet" href="http://shop.wwiz.kr/theme/basic/css/colorset_basic.css?ver=191202">
<script>
// 자바스크립트에서 사용하는 전역변수 선언
var g5_url = "http://shop.wwiz.kr";
var g5_bbs_url = "http://shop.wwiz.kr/bbs";
var g5_is_member = "1";
var g5_is_admin = "super";
var g5_is_mobile = "";
var g5_bo_table = "";
var g5_sca = "";
var g5_editor = "";
var g5_cookie_domain = "";
var max_width = "1200";
</script>
<script src="http://shop.wwiz.kr/js/jquery-1.12.4.min.js?ver=191202"></script>
</head>


<script>
/* 별점 is_radio=false 읽기 전용 */
function get_star(id,value,is_radio = true, fontsize, color) {
var wrapclass = readonly = j = '';
if(is_radio == false) {
readonly = 'readonly';
wrapclass = 'starfalse';
}
wrapheight = fontsize + 5;
divwidth = fontsize + 1;
left = Math.floor(fontsize/2);
divmargin = Math.floor(fontsize/3);

if(is_radio == false) {
var style = '<style>';
style += '.star_wrap { position: relative; display: flex; height: '+wrapheight+'px}\n';
style += '.star_wrap:after {clear: both; display: block; content: ""; }\n';
style += '.star_wrap .star_div { position: relative; display: flex; color: #dc3545; width: '+divwidth+'px; }\n';
style += '.star_wrap .star_div:last-child { margin-right: auto; }\n';
style += '.star_wrap .star_div:before { position: absolute; width: 100%; top: 0; bottom: 0; left: calc( 50% - '+left+'px); right: 0; font-family: "fontAwesome"; content: "\\f006"; font-size: '+fontsize+'px; color: '+color+'; line-height: 1; }\n';
style += '.star_wrap .star_div:after {clear: both; display: block; content: ""; }\n';
style += '.star_wrap .star_half:before { content: "\\f123"; }\n';
style += '.star_wrap .star_full:before { content: "\\f005"; }\n';
style += '.star_wrap .star_div .star_radio { position: relative; width: 50%;}\n';
style += '.star_wrap .star_div .star_radio:after {clear: both; display: block; content: ""; }\n';
style += '.star_wrap .star_div .star_radio .radio_star { z-index: -1; opacity: 0; }\n';
style += '.star_wrap .star_div .star_radio label { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: block; }\n';
style += '</style>';
} else {
var style = '<style>';
style += '#'+id+'.star_wrap { position: relative; display: flex; height: '+wrapheight+'px}\n';
style += '#'+id+'.star_wrap:after {clear: both; display: block; content: ""; }\n';
style += '#'+id+'.star_wrap .star_div { position: relative; display: flex; color: #dc3545; width: '+divwidth+'px; }\n';
style += '#'+id+'.star_wrap .star_div:last-child { margin-right: auto; }\n';
style += '#'+id+'.star_wrap .star_div:before { position: absolute; width: 100%; top: 0; bottom: 0; left: calc( 50% - '+left+'px); right: 0; font-family: "fontAwesome"; content: "\\f006"; font-size: '+fontsize+'px; color: '+color+'; line-height: 1; }\n';
style += '#'+id+'.star_wrap .star_div:after {clear: both; display: block; content: ""; }\n';
style += '#'+id+'.star_wrap .star_half:before { content: "\\f123"; }\n';
style += '#'+id+'.star_wrap .star_full:before { content: "\\f005"; }\n';
style += '#'+id+'.star_wrap .star_div .star_radio { position: relative; width: 50%;}\n';
style += '#'+id+'.star_wrap .star_div .star_radio:after {clear: both; display: block; content: ""; }\n';
style += '#'+id+'.star_wrap .star_div .star_radio .radio_star { z-index: -1; opacity: 0; }\n';
style += '#'+id+'.star_wrap .star_div .star_radio label { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: block; }\n';
style += '</style>';
}

var html = '<div id="'+id+'" class="star_wrap '+wrapclass+'">';
for(var k=0; k < 5; k++) {
i = (k * 2) + 1;
j = i + 1;
var ichecked = (i == value) ? 'checked' : '';
var jchecked = (j == value) ? 'checked' : '';

var starclass = '';
if( (i < value && j < value) || j == value ) {
starclass = 'star_full';
}
if (i == value) {
starclass = 'star_half';
}

if(is_radio == false) {
html += '<div class="star_div '+starclass+'">';
html += '<div class="star_radio"
2020-11-06 (금) 15:58:30
혹시 이거 php 따로 만드는거에요? 아니면 writeskin에 넣는거에요?
2020-11-06 (금) 15:57:10
<script>

// 아이디, 적용된 평점, true이면 평가가능, false이면 읽기 전용, 폰트크기, 색상
var star = get_star('id1',0,true,24,'#e83e8c');
document.write(star[0]); //css
document.write(star[1]); //별
</script>

이거는 listskin에 넣는거에요?
2020-11-06 (금) 16:02:41
링크 걸어주신 적용예 처럼 게시판 글쓰기에서 별점 점수 주고 리스트에 뜨게 하려는데 이거 안되네요
2020-11-06 (금) 16:05:11
별점 주는 것도 안뜨는데 어떻게 해야하는지 알려주시면 감사합니다
<script src="http://shop.wwiz.kr/js/jquery-1.12.4.min.js?ver=191202"></script>
js 파일을 따로 분리해 놨습니다. 해당 파일을 다운받으신 후 사용하시면 됩니다.
2020-11-06 (금) 18:37:10
js파일 소스보기 하니 코드 일부가 깨져있는데 상관없나요?
주석 달아놓은 거라 관계없습니다
2020-11-06 (금) 21:19:35
감사합니다!!!!!♡♡
2020-11-09 (월) 12:57:53
감사합니다. ^^
2020-11-10 (화) 15:09:38
대단하십니다. 멋지내요 ~
좋네요~
우와 감사합니다 ㅎㅎ
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
20-12-10 조회 7,381
20-12-08 조회 5,826
20-12-08 조회 8,462
20-12-05 조회 7,966
20-12-03 조회 7,080
20-12-03 조회 5,424
20-11-24 조회 6,256
20-11-24 조회 7,636
20-11-23 조회 6,019
20-11-22 조회 7,187
20-11-20 조회 5,460
20-11-19 조회 6,481
20-11-19 조회 5,366
20-11-19 조회 5,508
20-11-19 조회 5,916
20-11-14 조회 7,531
20-11-11 조회 7,410
20-11-09 조회 6,474
20-11-06 조회 7,887
20-11-05 조회 7,008
20-11-01 조회 6,949
20-10-30 조회 1.1만
20-10-28 조회 6,330
20-10-28 조회 7,004
20-10-27 조회 1.5만
20-10-27 조회 5,680
20-10-21 조회 5,908
20-10-20 조회 6,224
20-10-20 조회 6,372
20-10-14 조회 8,778