사이트 내 전체검색
폰트 크기 제어
로빈아빠
https://cmd.kr/javascript/675 URL이 복사되었습니다.

본문

폰트 크기 제어

<A href="javascript:PlusFont();">[크게]</A> <A href="javascript:MinusFont();">[작게]</A> <A href="javascript:SetArticleFont();">[저장]</A> <A href="javascript:SetDefaultFont();">[기본]</A>

<DIV id=article style="WORD-BREAK: break-all; LINE-HEIGHT: 180%; TEXT-ALIGN: left">
글내용
</DIV>
<SCRIPT language=javascript src="font.js"></SCRIPT>


font.js
		function SetDefaultFont() {
			var todayDate = new Date();
			var name = "ArticleFont";
			var expiredays = -1;
			var value = article.style.fontSize + "//" + article.style.fontFamily;
			todayDate.setDate( todayDate.getDate() + expiredays );
			document.cookie = name + "=" + value + "; path=/; expires=" + todayDate.toGMTString() + ";"
			document.location.reload();
		}
		
		function SetArticleFont() {
			var todayDate = new Date();
			var name = "ArticleFont";
			var expiredays = 365;
			var value = article.style.fontSize + "//" + article.style.fontFamily;
			todayDate.setDate( todayDate.getDate() + expiredays );
			document.cookie = name + "=" + value + "; path=/; expires=" + todayDate.toGMTString() + ";"
			alert("현재의 글꼴과 글자크기 상태로 저장했습니다");
		}

		function GetArticleFont(name){
			var nameOfCookie = name + "=";
			var x = 0;
			while ( x <= document.cookie.length )
			{
				var y = (x+nameOfCookie.length);
				if ( document.cookie.substring( x, y ) == nameOfCookie ) {
					if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
					endOfCookie = document.cookie.length;
					return document.cookie.substring( y, endOfCookie );
				}
				
				x = document.cookie.indexOf( " ", x ) + 1;
				
				if ( x == 0 ) break;
			}
					return "";
		}

		var Font;
		var fontsize;
		var fontface;
		var LineHeight = 16;

		temp = GetArticleFont("ArticleFont").split("//");

		if (temp != "") {
			if(temp[0] == "") {
				fontsize = 9;
				fontface = "Verdana";
			} else {
			fontsize = parseInt(temp[0]);
			fontface = temp[1];
				if (fontsize > 9) {
					LineHeight = 12 + (fontsize-9);;			
				} else {
					LineHeight = 12;
				}
			}
			
		} else {
			fontsize = 9;
			fontface = "Verdana";
		}
		article.style.fontSize = fontsize +"pt";
		article.style.fontFamily = fontface;
		article.style.lineHeight = LineHeight + "pt";

		function PlusFont() {
			if (fontsize <= 15) {
			article.style.fontSize = (fontsize + 1) +"pt";
			article.style.lineHeight = LineHeight + 1 + "pt";
			fontsize = fontsize + 1;			
			LineHeight = LineHeight + 1;
			}
		}

		function MinusFont() {	
			if (fontsize >= 9) {
			article.style.fontSize = (fontsize - 1) +"pt";
			article.style.lineHeight = LineHeight - 1 + "pt";
			fontsize = fontsize - 1;
			LineHeight = LineHeight - 1;
			}
		}
		
		function FontCase(Font) {
			article.style.fontFamily = Font;
		}
		
		function SetFont() {
			var todayDate = new Date();
			todayDate.setDate( todayDate.getDate() + 365 );
			document.cookie = "Font = " + article.style.fontSize + "; path=/; expires=" + todayDate.toGMTString() + ";"			
		}

댓글목록

등록된 댓글이 없습니다.

831 (3/17P)

Search

Copyright © Cmd 명령어 3.129.211.116