시작페이지로 즐겨찾기추가
로그인
회원가입 l 출석체크 l 마이페이지 l CGIMALL
드래그 가능한 깔끔한 계산기 : happycgi
자료실 사이트등록 랭킹100 프로그램리뷰 관리자추천자료 초보가이드
커뮤니티
전체 펼쳐보기
퀵메뉴링크 jquery , CSS , PHP , Javascript , 무료폰트 , ASP
상세검색
 > JAVASCRIPT > javascript 소스창고 > 계산기 > 드래그 가능한 깔끔한 계산기 상세정보
사이트등록
클라우드태그
Javascript
PHP
html
CSS
asp
API
mysql
jquery
image
slide
mobile
메뉴
게시판
현재접속자 17 새로고침
드래그 가능한 깔끔한 계산기
소스통계정보 오류신고 및 문의
해피팀
네티즌
트위터로 보내기 페이스북으로 보내기 네이버로공유
소스분류 계산기
다운로드 횟수 1413 회
간단설명 전자계산기를 마우스로 드래그할수있습니다. 디자인도 깔끔하고 세련
평가하기 훌륭함 매우좋음 좋음 괜찮음 보통 별로
홈페이지바로가기 소스다운로드 데모 미리보기 스크랩하기

자바로만든 전자계산기

1. 기본적인 전자 계산기 기능이 갇춰져있습니다.

2. 반투명에 깔끔한 디자인이 여느 웹사이트에 붙여놔도 손색이 없습니다.

3. 마우스로 드래그 시켜서 이동시킬수있습니다. 레이아웃상 어느 위치에 붙여도 괜찮습니다.

 

아래는 본문스크립트입니다.

<HTML>
<HEAD>
    <TITLE>해피CGI</title>

<style type="text/css">
<!--
#demo {
    margin:50px;
}
#calculator {
    filter:alpha(opacity=85);
    -moz-opacity:.85;
    opacity:.85;
}
.drag
{
    position:relative;
    cursor:hand
}
#calculator
{
    background-color:#F4F4F4;
    cursor:move;
    width:190px;
}
.calculatorcontainer
{
    padding:5px;
    border-top:1px solid #C0C0C0;
    border-left:1px solid #C0C0C0;
    border-right:2px outset #C0C0C0;
    border-bottom:2px outset #C0C0C0;
}
#calculator #control
{
    text-align:right;
}
#calculator input
{
    width:40px;
    height:30px;
    margin:2px;
    background-color:#FFF;
    font-family:verdana,arial,helvetica,sans-serif;
    font-size:0.95em;
    border:1px solid #C0C0C0;
    cursor:hand;
    cursor:pointer;
}
#calculator img
{
    border:0;
}
#calculator #result
{
    width:173px;
    font-size:1.3em;
    padding:3px;
    cursor:text;
}
#calculator .operation
{
    color:#999;
    font-weight:bold;
    background-color:#DDD;
}
#calculator .equals
{
    color:#FFF;
    font-weight:bold;
    background-color:#336699;
}
#version
{
    float:left;
    padding:2px 0px 0px 2px;
    font-size:0.65em;
}
#version a
{
    color:#333;
    cursor:move;
    text-decoration:none;
}

-->
</style>

<script type="text/javascript">
<!--
var calculation = "";
var resultDone = false;

function addToCalc(val) {
  if(isNaN(val) && isNaN(calculation.substring(calculation.length-1, calculation.length)))
    return false;

  if(!isNaN(val) && resultDone) {
    resetCalc();
    resultDone = false;
  } else if(isNaN(val) && resultDone) {
    resultDone = false;
  }
  calculation += val;
  showResult();
}

function addToCalcDirect(val) {
  calculation = val;
}

function resetCalc() {
  calculation = "";
  showResult();
}

function positiveNegative() {
  if(calculation.substring(0, 1) == "-")
    calculation = calculation.substring(1, calculation.length);
  else
    calculation = "-" + calculation;
  showResult();
}

function calculate() {
  if(calculation != "") {
    try {
      calculation = eval(calculation);
    } catch(e) {
      reportError("Error!");
    }
    resultDone = true;
    showResult();
  }
  else
    return false;
}

function percentage() {
  try {
    calculation = eval(calculation) / 100;
  } catch(e) {
    reportError("Error!");
  }
  resultDone = true;
  showResult();
}

function squareRoot()
{
  try {
    calculation = Math.sqrt(eval(calculation));
  } catch(e) {
    reportError("Error!");
  }
  resultDone = true;
  showResult();
}

function showResult() {
  calculation = calculation.toString();
  if(calculation == "NaN") {
    reportError("Error!");
  } else {
    document.getElementById("result").value = calculation;
  }
}

function reportError(msg) {
  calculation = msg;
  document.getElementById("result").value = msg;
}

function closeCalculator() {
  document.getElementById("calculator").style.display = "none";
}

function about() {
  msg = "CJ Floating Calculator\n=============\n\n";
  msg += "Developed by James Crooke\nhttp://www.cj-design.com";
  alert(msg);
}

var ie = document.all;
var ns6 = document.getElementById && !document.all;
var dragapproved=false;
var z, x, y;

function move(e) {
  if (dragapproved) {
    z.style.left=ns6? temp1+e.clientX-x: temp1+event.clientX-x;
    z.style.top=ns6? temp2+e.clientY-y : temp2+event.clientY-y;
    return false;
  }
}

function drags(e) {
  if (!ie&&!ns6)
  return;
  var firedobj = ns6? e.target : event.srcElement;
  var topelement = ns6? "HTML" : "BODY";
  while (firedobj.tagName != topelement&&firedobj.className != "drag") {
    firedobj = ns6? firedobj.parentNode : firedobj.parentElement;
  }
  if (firedobj.className == "drag") {
    dragapproved = true;
    z = firedobj;
    temp1 = parseInt(z.style.left+0);
    temp2 = parseInt(z.style.top+0);
    x = ns6? e.clientX: event.clientX;
    y = ns6? e.clientY: event.clientY;
    document.onmousemove=move;
    return false;
  }
}
document.onmousedown=drags;
document.onmouseup=new Function("dragapproved=false");
// -->
</script>
</HEAD>

<BODY>
전자계산기를 드래그 할 수 있습니다.
<div id="demo">
  <form onsubmit="calculate(); return false;">
  <div id="calculator" class="drag">
    <div class="calculatorcontainer">
      <div id="control"><a href="#" onclick="closeCalculator();return false"><img src="http://www.blueb.co.kr/SRC/javascript/image4/close1.gif" style="position:relative;top:-1px"/></a></div>
      <input type="text" name="input" size="16" id="result" onclick="this.focus()" onkeyup="addToCalcDirect(this.value)"><br />
      <input type="button" value="1" onclick="addToCalc(this.value)"><input type="button" value="2" onclick="addToCalc(this.value)"><input type="button" value="3" onclick="addToCalc(this.value)"><input type="button" value="+" onclick="addToCalc(this.value)" class="operation"><br />
      <input type="button" value="4" onclick="addToCalc(this.value)"><input type="button" value="5" onclick="addToCalc(this.value)"><input type="button" value="6" onclick="addToCalc(this.value)"><input type="button" value="-" onclick="addToCalc(this.value)" class="operation"><br />
      <input type="button" value="7" onclick="addToCalc(this.value)"><input type="button" value="8" onclick="addToCalc(this.value)"><input type="button" value="9" onclick="addToCalc(this.value)"><input type="button" value="*" onclick="addToCalc(this.value)" class="operation"><br />
      <input type="button" value="+/-" onclick="positiveNegative()" class="operation"><input type="button" value="0" onclick="addToCalc(this.value)"><input type="button" value="." onclick="addToCalc(this.value)" class="operation"><input type="button" value="/" onclick="addToCalc(this.value)" class="operation"><br />
      <input type="button" value="sqrt" onclick="squareRoot()" class="operation"><input type="button" value="%" onclick="percentage()" class="operation"><input type="button" value="c" onclick="resetCalc()" class="operation"><input type="button" value="=" onclick="calculate()" class="equals">
    </div>
  </div>
  </form>
</div>


네티즌 의견   이용하신 자료의 후기를 자유롭게 작성하세요. (상업적인 광고 및 도배성 글 등은 사전통보없이 삭제될 수 있습니다.)
내용 아이디 의견남기기
1-0.9=0.09999999999999998
2008-12-30 15:35:01
howsoft
찬성 57
반대 60
데모에서 .. 5-4.9 를 하면 0.09999999999999964 라고 나오네요.
소숫점 계산에서 에러가 있는 것 같습니다.
2008-12-30 15:33:54
howsoft
찬성 67
반대 62
1
이름
내용
:네맞아요: :화나는군요: :잠와: :우울해: :이건아냐: :왕하하: 왕웃음~ 놀램~
평가하기 훌륭함 매우좋음 좋음 괜찮음 보통 별로
도배방지키
 20458111 보이는 도배방지키를 입력하세요.