简体   繁体   English

窗口大小调整时查看中断

[英]View disrupts on Window resize

I've created a page using squares. 我已经使用正方形创建了一个页面。 The squares combine to make a particular word. 正方形组合成一个特定的单词。 But when I resize the window, the squares disrupt their place in a haphazard way. 但是,当我调整窗口大小时,正方形会随意摆弄它们的位置。 How I can change my CSS or javascript so that the squares retain their original positions on window resize? 如何更改CSSjavascript ,以使正方形在调整窗口大小时保留其原始位置?

You can view the page at : http://www.tryst-iitd.com/13/beta 您可以在以下页面查看页面: http : //www.tryst-iitd.com/13/beta

I've included the following code to take care of the resizing, still the problem remains unsolved. 我提供了以下代码来调整大小,但是问题仍然没有解决。

<script type="text/javascript">
$(function () {
    var screenWidth = $(window).width() + "px";
    var screenHeight = $(window).height() + "px";
    $("#container").css({
        width: screenWidth,
        height:screenHeight,
    });
    $(window).resize( function () {
        var screenWidth = $(window).width() + "px";
        var screenHeight = $(window).height() + "px";
        $("#container").css({
            width: screenWidth,
            height:screenHeight,
        });
    });
});
</script>

The square is disrupted because the width of the container is adjusted automatically whenever you resize your window. 正方形被打乱了,因为每当您调整窗口大小时,容器的宽度都会自动调整。 Set a fix value or set a minimum width for the square and container should fix the problem. 设置正方形的固定值或最小宽度,容器应解决此问题。 The square width is in %. 正方形宽度以%为单位。

Also, the window resize event itself is useless because the div (id=container) is adjusted according to the width of the body tag 同样,窗口调整大小事件本身是没有用的,因为div(id = container)根据body标签的宽度进行了调整

Set the position and size of your squares in percentages and your resize code will works fine. 以百分比设置正方形的位置和大小,您的大小调整代码将正常工作。

Also, set the min-width / min-height CSS properties will prevent your squares from being too small. 另外,设置min-width / min-height CSS属性将防止正方形过小。

Your problem is that your css margins are fixed width, so even if squares width are in %, margins causes this issues. 您的问题是css页边距是固定宽度的,因此即使正方形宽度以%为单位,页边距也会导致此问题。 As an example, try disabling wrap1 and wrapalphabet css classes, you will see that your design will be much more responsive. 例如,尝试禁用wrap1wrapalphabet css类,您将看到您的设计将更加敏感。

You probably have to rethink the way you deal with margin/padding to get the results you expect. 您可能必须重新考虑处理边距/填充的方式才能获得预期的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM