一个测试有3个部分,其中第一部分必须大如浏览器窗口的jQuery和Javascript
A test of 3 sections, where the first must the big as the browser window jQuery and Javascript
EDIT:通过在页面顶部书写Doctype -来解决"& lt;!DOCTYPE html>"(标签之间没有空格<,>和其他字符)
我正在做一个包含四个部分的页面的测试。第一个参数必须是浏览器窗口的高度。因此,为了做到这一点,我测试了jQuery和Javascript代码。但是,虽然JS-pure代码可以工作,但jQuery的代码却不行。代码如下:
jQuery:$("section:first").css("min-height", $(window).height());
$(window).resize(function() {
$("section:first").css("min-height", $(window).height());
});
Javascript: var first = document.getElementsByTagName("section")[0];
first.style.minHeight = window.innerHeight + "px";
window.onresize = function() {
first.style.minHeight = window.innerHeight + "px";
}
我有一个iMac 1920x1080和我的Chrome浏览器的高度是896px,但如果我尝试使用jQuery代码(这不会得到控制台错误!),最小高度数将通过调整窗口大小(向上或向下)的高度(总是向上)和其他部分的基数增长。有人知道为什么吗?
有HTML和CSS:
body {
margin: 0;
background-image: url("images/bg.jpg");
background-repeat: repeat;
background-position: center;
background-attachment: fixed;
background-size: 713px 518px;
}
.content {
background-color: #FFF;
}
.internal {
position: relative;
padding: 1% 20px;
margin: 0 auto;
border-bottom: 1px solid #21D561;
}
<section> Some content here </section>
<section class="content">
<div class="internal">
<p>Here a big Lorem Ipsum in eight paragraphs</p>
</div>
</section>
<section class="content">
<div class="internal">
<p>Here a big Lorem Ipsum in six paragraphs</p>
</div>
</section>
<section class="content">
<div class="internal">
<p>Here a big Lorem Ipsum in six paragraphs</p>
</div>
</section>
您可以在这里看到错误的结果:http://syrafiles.esy.es/learning/Static_Section/
在你的纯JS中你写:
var first = document.getElementsByTagName("section")[0];
first.style.minHeight = window.innerHeight + "px";
window.onresize = function() {
first.style.minHeight = window.innerHeight + "px";
}
而忽略+ "px"
:
$("section:first").css("min-height", $(window).height());
$(window).resize(function() {
$("section:first").css("min-height", $(window).height());
});
试试相反:
$("section:first").css("min-height", $(window).height() + "px");
$(window).resize(function() {
$("section:first").css("min-height", $(window).height() + "px");
});
.height()
只返回一个整数,您还需要在这里添加+ "px"
,就像您在纯JS中做的那样
相关文章:
- 访问布局信息是否也会导致浏览器重排
- 内部分区字体大小获胜'调整浏览器窗口大小时不会随媒体查询而更改
- 如何使用phaser使html5游戏在移动设备浏览器上运行
- 有时数据是't显示在浏览器中
- 使图像在单击时展开到不大于浏览器
- fetch() 函数未在 Ubuntu Chromium 浏览器上定义
- 不同浏览器中的空白字符正则表达式行为
- 在Windows 10中自动执行例行程序(主要与浏览器交互)
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- Windows形成web浏览器控件和Javascript更改的DOM
- 如何临时暂停浏览器渲染,然后恢复整个页面
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 是什么让一个“;Uncaught RangeError:超过了最大调用堆栈大小“;错误(Chrome,在其他浏览器中显示
- 谷歌地图API v3不适用于移动浏览器或PhoneGap
- 如何防止html页面的一部分缓存在浏览器中
- 确定网页的一部分在浏览器中保持可见的时间
- 弹出窗口浏览器仍然是Windows主页的一部分
- iphone应用程序浏览器的书签栏隐藏了我网站的一部分
- 在浏览器中使用javascript __proto__作为实现算法的一部分
- 我如何使CSS背景的一部分完美地适合浏览器