[英]javascript breaks when I want to print a page
So I created this webpage using JQuery. 因此,我使用JQuery创建了此网页。 I use this code to resize the images on my page so that they fit in squares.
我使用此代码来调整页面上图像的大小,以使其适合正方形。
<script type="text/javascript">
$(document).ready(function(){
var height = $('.square').width();
$('.square').css('height', height);
window.onresize = function(event) {
var height = $('.square').width();
$('.square').css('height', height);
}
});
</script>
This works perfectly. 这很完美。 The images resize to squares when I load the page or when i resize my browser window.
当我加载页面或调整浏览器窗口大小时,图像会调整为正方形。 The problem is when I go and press print page (I'm using google Chrome).
问题是当我去按打印页面时(我使用的是谷歌浏览器)。 The printer preview loads the page as if these two scripts don't exist.
打印机预览将加载页面,就好像这两个脚本不存在一样。 So the images are their original sizes.
因此,图像是其原始大小。
Any Ideas ? 有任何想法吗 ?
If you just want to keep images square, you might not even need javascript, the below gives you an example, the bonus it's responsive.. 如果您只是想使图像保持方形,则可能甚至不需要JavaScript,下面提供了一个示例,它具有响应能力。
.pic-wrapper { width: 40%; float: left; margin-right: 20px; } .pic { width: 100%; padding-bottom: 100%; background-image: url('http://i.imgur.com/uTDpE6J.jpg') }
<div class="pic-wrapper"> <div class="pic"> </div> </div> <div class="pic-wrapper"> <div class="pic"> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.