Dynamic Fonts动态设置字体大小存入Cookie
代码
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3
4 <head>
5 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
6 <title>Dynamic Fonts动态设置字体大小存入Cookie</title>
7 <meta name="Author" content="涂聚文" />
8 <meta name="Keywords" content= "自定义字体 缔友计算机信息技术有限公司 捷为工作室 www.dupcit.com,Font-resizing javascript – Text Resizing javascript" />
9 <meta name="Description" content="自定义字体 缔友计算机信息技术有限公司 捷为工作室,Font-resizing – Text Resizing javascript" />
10 <link rel="shortcut icon" href="http://www.dupcit.com/favicon.ico" type="image/x-icon" />
11 <link rel="icon" href="http://www.dupcit.com/favicon.ico" type="image/ico" />
12
13 <script type="text/javascript">
14 function $(v) { return(document.getElementById(v)); }
15 function cookieStab(f,v) { document.cookie=f+'='+v+'; path=/'; }
16 function cookieGrab(f) { var c=document.cookie.split(';'); f=f+"="; for(var i in c) { var v=trim(c[i]); if(v.indexOf(f)==0) { return(v.substr(f.length,v.length)); } } }
17 function mkStyle(v,s) { v=zero(v); if(v) { var b=!s?(zero($('test').style.fontSize)+v):v; $('test').style.fontSize=b+'px'; cookieStab('fontSize',b); } }
18 function trim(v) { return(v.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"")); }
19 function zero(v) { v=parseInt(v); return(!isNaN(v)?v:0); }
20
21 window.onload=function() { mkStyle(cookieGrab('fontSize'),1); };
22
23 </script>
24 </head>
25
26 <body>
27 <a href="#" onclick="mkStyle(1); return false;" title="increase font size">larger</a>
28 <a href="#" onclick="mkStyle(-1); return false;" title="decrease font size">smaller</a>
29
30 <div id="test">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc.
31 </div>
32 </body>
33
34 </html>
35
2 <html xmlns="http://www.w3.org/1999/xhtml">
3
4 <head>
5 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
6 <title>Dynamic Fonts动态设置字体大小存入Cookie</title>
7 <meta name="Author" content="涂聚文" />
8 <meta name="Keywords" content= "自定义字体 缔友计算机信息技术有限公司 捷为工作室 www.dupcit.com,Font-resizing javascript – Text Resizing javascript" />
9 <meta name="Description" content="自定义字体 缔友计算机信息技术有限公司 捷为工作室,Font-resizing – Text Resizing javascript" />
10 <link rel="shortcut icon" href="http://www.dupcit.com/favicon.ico" type="image/x-icon" />
11 <link rel="icon" href="http://www.dupcit.com/favicon.ico" type="image/ico" />
12
13 <script type="text/javascript">
14 function $(v) { return(document.getElementById(v)); }
15 function cookieStab(f,v) { document.cookie=f+'='+v+'; path=/'; }
16 function cookieGrab(f) { var c=document.cookie.split(';'); f=f+"="; for(var i in c) { var v=trim(c[i]); if(v.indexOf(f)==0) { return(v.substr(f.length,v.length)); } } }
17 function mkStyle(v,s) { v=zero(v); if(v) { var b=!s?(zero($('test').style.fontSize)+v):v; $('test').style.fontSize=b+'px'; cookieStab('fontSize',b); } }
18 function trim(v) { return(v.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,"")); }
19 function zero(v) { v=parseInt(v); return(!isNaN(v)?v:0); }
20
21 window.onload=function() { mkStyle(cookieGrab('fontSize'),1); };
22
23 </script>
24 </head>
25
26 <body>
27 <a href="#" onclick="mkStyle(1); return false;" title="increase font size">larger</a>
28 <a href="#" onclick="mkStyle(-1); return false;" title="decrease font size">smaller</a>
29
30 <div id="test">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc.
31 </div>
32 </body>
33
34 </html>
35
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)