调整窗口大小时自动调整文本大小(字体大小)? [英] auto resize text (font size) when resizing window?

查看:191
本文介绍了调整窗口大小时自动调整文本大小(字体大小)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图(徒然)构建一个页面,其元素将随着我改变窗口大小而调整大小。我有它的工作在css的图像没有问题,但我似乎无法完成相同的文本,我不知道它甚至可能在CSS。我不能找到一个jquery脚本来实现这一点。

I have been trying(in vain) to build a page whose elements would resize as I changed the window size. I have it working in css for images no problem, but I can't seem to accomplish the same for text, and I am not sure it is even possible in CSS. And I can't seem to find a jquery script that accomplishes this.

当用户调整窗口大小时,我本质上希望页面动态和流畅地缩放,没有用户必须调用页面缩放。

When a user resizes the window, I essentially want the page to scale dynamically and fluidly, without the user having to invoke page zoom. This works fine on my img divs via css, but not for the text, which stays the same size.

任何想法?

推荐答案

我不得不自己这样做。我做的是,我设置的基本文本大小的身体,和所有其他大小的百分比。然后我使用一个简单的jQuery脚本来改变窗口大小的基本大小。其他大小然后更新。

I've had to do this myself. What I did was that I set a base text size for the body, and percentages for all other sizes. I then used a simple jQuery script to change the base size on window resize. The other sizes then update as well.

我使用这样的:

$(function() {
    $(window).bind('resize', function()
    {
        resizeMe();
        }).trigger('resize');
    });

在resizeMe函数中,我有:

and in the resizeMe-function, I had this:

//Standard height, for which the body font size is correct
var preferredHeight = 768;
//Base font size for the page
var fontsize = 18;

var displayHeight = $(window).height();
var percentage = displayHeight / preferredHeight;
var newFontSize = Math.floor(fontsize * percentage) - 1;
$("body").css("font-size", newFontSize);

这篇关于调整窗口大小时自动调整文本大小(字体大小)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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