用于更改字体大小的JavaScript [英] JavaScript to change Font Size

查看:90
本文介绍了用于更改字体大小的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手使用javascript和css一起使用,所以请耐心等待....


我注意到ESPN网站以及其他一些网站,他们实现了一个漂亮的小脚本,允许用户通过按一个更小或更大的字母的gif来选择更大或更小的字体大小(参见 http://sports.espn.go.com/golf/news/story?id=2463902 举个例子;控件是在右栏中,在广告下面。


有人可以指向我这样做的脚本,或者(甚至更好)建议一个很好的参考,以更好地理解这种技术吗? />

我们非常感谢您的帮助。


-Stephen

I am new to using javascript in conjunction with css, so please bear with me....

I have noticed that on the ESPN site, as well as some others, they implement a nifty little script that allows the user to select a larger or smaller font size by pressing a gif of a smaller or larger letter (see http://sports.espn.go.com/golf/news/story?id=2463902 for an example; the control is in the right column, below the ads).

Can someone either point me to a script that does this or (even better) suggest a good reference to better understand this technique?

Your assistance is appreciated.

-Stephen

推荐答案

所以它''这是一个非常聪明的小技巧,我建议您查看页面源和DOM(使用Cource的FireFox,因为IE不会这样做或者具有良好的页面搜索功能)。


在页面源代码中查找fontsize和text11。但基本上它会执行以下操作
So it''s quite a clever little trick, I suggest that you look at the page source and DOM (using FireFox of cource since IE doesn''t do this or have good page search facilities).

In the page source look for fontsize and text11. But basically it does the following
  1. 从cookie加载字体大小,如果cookie不存在则使用默认值
  2. 使用javascript在页面顶部编写一小段样式代码,定义样式类.text11,其中字体大小从cookie中加载。该样式已经应用于作者希望控制其大小的div。
  3. 使用javascript(尽管这只是显示所选大小)写入4个链接以更改字体大小。这些调用了一个javascript函数,它将字体大小的新值写入cookie,然后重新加载页面。



我会说它很容易从中提取你引用的页面。


I would say that it is all easily liftable from the page you reference.


这只是我需要的指导。谢谢!
This is just the guidance that I needed. Thanks!



所以这是一个非常聪明的小技巧,我建议您查看页面源和DOM(使用FireFox) cource因为IE没有这样做或者有很好的页面搜索功能。)


在页面源代码中查找fontsize和text11。但基本上它会执行以下操作
So it''s quite a clever little trick, I suggest that you look at the page source and DOM (using FireFox of cource since IE doesn''t do this or have good page search facilities).

In the page source look for fontsize and text11. But basically it does the following
  1. 从cookie加载字体大小,如果cookie不存在则使用默认值
  2. 使用javascript在页面顶部编写一小段样式代码,定义样式类.text11,其中字体大小从cookie中加载。该样式已经应用于作者希望控制其大小的div。
  3. 使用javascript(尽管这只是显示所选大小)写入4个链接以更改字体大小。这些调用了一个javascript函数,它将字体大小的新值写入cookie,然后重新加载页面。



我会说它很容易从中提取你引用的页面。


I would say that it is all easily liftable from the page you reference.



你好。


正如你所看到的,我在这里是全新的,并且全新的CSS和javascript。我试图在我的网站上实现相同的脚本,并遇到麻烦。我从上面引用的那个页面中提取了字体大小脚本,但它不起作用。我是否需要创建样式表并添加一些代码才能使此脚本在我的站点上运行?我搜索了espn源代码,但是看不到样式表的引用位置。


对于这样一个新手问题很抱歉,这让我很沮丧。或者,如果你知道一个现成的脚本将执行相同的功能,我现在很乐意使用它,并花时间学习它后来的意思,因为我在紧要关头。 />

再次感谢你

Hello.

As you can see I am brand new here and brand new to CSS and javascript. I am trying to implement the same script on my site and am having troubles. I lifted the font size script from that page referenced above but it isn''t working. Do I need to create a Style Sheet and add some code to it for this script to work on my site? I have searched the espn source code but can''t see where a style sheet is referenced.

Sorry for such a newbie question but this has me frustrated. Alternatively, if you know of a ready-made script that will perform the same function, i''d be happy to use that for now and take the time to learn what it means later as i''m in a pinch.

thank you again


这篇关于用于更改字体大小的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆