html - 单击时使圆形 div 展开以填充整个页面

标签 html css

<分区>

我的页面中间有一个圆形 div,我想让它在单击时扩展到整个屏幕大小。有什么建议吗?

如果可能的话,我希望它能顺利过渡。

最佳答案

你可以用 css 和 javascript

div.small {
    background: #f00;
    border-radius: 50%;
    width: 100px;
    height: 100px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -50px;
    margin-top: -50px;
    transition: all .5s;
}

div.big {
    width: 100%;
    height: 100%;
    top: 0;
    margin-top: 0;
    left: 0;
    margin-left: 0;
    border-radius: 0;
    background: #0f0;
}

JS(我使用的是 zepto,但 jquery 是一样的)

$(window).on("click", ".small", function() {
    me = this;
    setTimeout( function() { $(me).addClass("big"); }, 1 );
});

$(window).on("click", ".big", function() {
    me = this;
    setTimeout( function() { $(me).removeClass("big"); }, 1 );
});

HTML

<div class="small"></div>

http://jsfiddle.net/frapporti/Vc492/


没有javascript

CSS

label {
    background: #f00;
    border-radius: 50%;
    width: 100px;
    height: 100px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-left: -50px;
    margin-top: -50px;
    transition: all .5s;
}

input:checked + label {
    width: 100%;
    height: 100%;
    top: 0;
    margin-top: 0;
    left: 0;
    margin-left: 0;
    border-radius: 0;
    background: #0f0;
}

input {
   visibility: hidden;
   position: absolute;
}

HTML

<input id="hidden-checkbox" type="checkbox"></input>
<label for="hidden-checkbox"></label>        

参见:http://jsfiddle.net/frapporti/85qfu/

关于html - 单击时使圆形 div 展开以填充整个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23812931/

相关文章:

php - JQuery 多重过滤器

css - 检查器中 "auto"、 "inherit"等 CSS 属性的实际值?

html - 基础重叠响应图像

javascript - 流体图像翻转 Twitter Bootstrap Rails

javascript - 使用 Javascript 通过 PHP 变量设置 HTML Date 元素的值

javascript - 通过html传递表单参数

css - onmouseover/onmouseout 上的过渡不起作用?

html - 显示 Jpeg 时,浏览器显示的大小约为应有大小的两倍

html - IE 溢出滚动

javascript - 如何在 javascript for 循环中呈现大块 html