小编ant*_*ver的帖子

CSS的背景大小背后的数学是什么:封面

我正在创建一个"图像生成器",用户可以上传图像并在其上添加文本和/或绘图.输出的图像是固定大小(698x450).

在客户端,当用户上传他们的图像时,它被设置为具有背景大小:封面的698x450的div的背景.这使它很好地填补了这个区域.

最终的组合图像由PHP使用GD函数生成.我的问题是,如何在PHP中使用与在CSS中相同的方式来扩展图像.我希望PHP脚本的结果看起来像在CSS中设置图像一样.有谁知道浏览器如何使用background-size:cover计算如何适当缩放图像?我想把它翻译成PHP.

谢谢

css gd css3

22
推荐指数
3
解决办法
4572
查看次数

Chrome onpopstate/pushState错误?

首先,我不完全确定我正在做什么或期望是对的.似乎没有太多关于此的文档,但我读过的内容表明这应该有效.

我在尝试使用history.pushState时遇到了一些问题,所以我最终制作了一个演示页面,看看出了什么问题.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" ></script>
<script>

window.onpopstate = function()
{
    var d = new Date;
    console.log(d.toString());
    console.log(document.location.href);
};

$(document).ready(function()
{

    $('#push').click(function()
    {
        var rand = Math.random();
        history.pushState( {'number':rand} , 'Test '+rand , '/test/'+rand );
        return false;
    });

});

</script>

</head>

<body>

<a href="#" id="push">New state</a>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

当我点击"新状态"链接时,我希望在控制台中看到onpopstate函数已被触发,我将看到一个新的url(类似于test/[number]).

chrome中地址栏中的位置确实会更新,但onpopstate事件永远不会触发.然后,当我单击浏览器中的后退按钮时,看起来多个popstate事件正在触发.看来,无论何时我使用浏览器导航按钮,应该触发的每个popstate事件都会同时发生.

这有点难以解释.这是我期望在控制台中看到的内容.

加载页面.Chrome会在页面加载时触发初始popstate事件

popstate.html:13Sat 2011年11月19日16:23:48 GMT + 0000(GMT标准时间)

popstate.html:14http://example.com/popstate.html

单击"新状态"链接.地址栏中的位置更新为http://example.com/test/0.06458491436205804.

2011年11月19日星期六16:23:53 GMT + 0000(格林威治标准时间标准时间)

popstate.html:14http://example.com/test/0.06458491436205804

单击浏览器中的后退按钮.地址栏中的网址返回/popstate.html

popstate.html:13Sat 2011年11月19日16:26:27 GMT …

javascript html5 google-chrome pushstate

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

css ×1

css3 ×1

gd ×1

google-chrome ×1

html5 ×1

javascript ×1

pushstate ×1