정보 보관 ver1.0

파일 선택(기본 스타일이 아닌 사용자 정의)

James Wetzel 2012. 9. 20. 19:30



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head>

    <title>Untitled Page</title>

        <style type="text/css">

            .file-wrapper {

              cursor: pointer;

              display: inline-block;

              overflow: hidden;

              position: relative;

            }

            .file-wrapper input {

              cursor: pointer;

              font-size: 100px;

              height: 100%;

              filter: alpha(opacity=1);

              -moz-opacity: 0.01;

              opacity: 0.01;

              position: absolute;

              right: 0;

              top: 0;

            }

            .file-wrapper .button {

              background: #79130e;

              -moz-border-radius: 5px;

              -webkit-border-radius: 5px;

              border-radius: 5px;

              color: #fff;

              cursor: pointer;

              display: inline-block;

              font-size: 11px;

              font-weight: bold;

              margin-right: 5px;

              padding: 4px 18px;

              text-transform: uppercase;

            }

        </style>

        <script type="text/javascript">

            var SITE = SITE || {};


            SITE.fileInputs = function () {

                var $this = $(this),

                $val = $this.val(),

                valArray = $val.split('\\'),

                newVal = valArray[valArray.length - 1],

                $button = $this.siblings('.button'),

                $fakeFile = $this.siblings('.file-holder');

                if (newVal !== '') {

                    $button.text('Photo Chosen');

                    if ($fakeFile.length === 0) {

                        $button.after('<span class="file-holder">' + newVal + '</span>');

                    } else {

                        $fakeFile.text(newVal);

                    }

                }

            };


            $(document).ready(function () {

                $('.file-wrapper input[type=file]').bind('change focus click', SITE.fileInputs);

            });

        </script>

</head>

<body>



<span class="file-wrapper">

  <input type="file" name="photo" id="photo" />

  <span class="button">Choose a Photo</span>

</span>


</body>

</html>



이미지를 사용하는 경우

<style type="text/css">

            .file-wrapper {

              cursor: pointer;

              display: inline-block;

              overflow: hidden;

              position: relative;

            }

            .file-wrapper input {

              cursor: pointer;

              font-size: 100px;

              height: 100%;

              filter: alpha(opacity=1);

              -moz-opacity: 0.01;

              opacity: 0.01;

              position: absolute;

              right: 0;

              top: 0;

            }

            .file-wrapper .button {              

              background-image:url('./images/mt_04.png');

              -moz-border-radius: 5px;

              -webkit-border-radius: 5px;

              border-radius: 5px;

              color: #fff;

              cursor: pointer;

              display: inline-block;

              font-size: 11px;

              font-weight: bold;

              text-transform: uppercase;

              width:152px;

              height:25px;

            }

        </style>


<span class="file-wrapper">

              <input type="file" name="photo" id="File1" />

              <span class="button"></span>

            </span>


728x90
반응형