简体   繁体   English

浏览器上的流体背景图像调整大小

[英]Fluid background image on browser resize

I want to achieve the fluid background image effect that you can see in this webpage: http://217.116.9.130/test2.html (taken from zara.com) 我想在这个网页上看到流畅的背景图像效果: http ://217.116.9.130/test2.html(取自zara.com)

If you resize your browser to the left the woman in the image goes left with your resizing. 如果您将浏览器调整到左侧,则图像中的女性将继续调整大小。 I've taken the code from zara.com but I suspect the effect is done by a language I don't know. 我从zara.com上获取了代码,但我怀疑这种效果是由我不知道的语言完成的。

Does anyone know and can give a clue (or hand me a link) on how to do it using jquery, css, ajax or php? 有没有人知道并且可以使用jquery,css,ajax或php给出如何使用它的线索(或给我一个链接)?

Thanks a lot 非常感谢

You are probably looking for this: http://css-tricks.com/perfect-full-page-background-image/ 你可能正在寻找这个: http//css-tricks.com/perfect-full-page-background-image/

It's quite simple to implement so no additional comments needed. 它实现起来非常简单,因此无需其他注释。

you can use css3 cover property. 你可以使用css3封面属性。 for it 为了它

.container{
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
}

for check this link http://css-tricks.com/perfect-full-page-background-image/ 查看此链接 http://css-tricks.com/perfect-full-page-background-image/

For example, if your background image is contained in your body tag, then the CSS should contain the background image assignment and then include: 例如,如果您的背景图片包含在您的body标签中,那么CSS应该包含背景图片分配,然后包括:

top: 0;
bottom: 0;
left: 0;
right: 0;

This way - when the window resizes - the background immediately changes with it. 这样 - 当窗口调整大小时 - 背景立即随之改变。 Same principle for providing an overlay for a modal dialog. 为模态对话框提供叠加层的原理相同。

do a css styling 做一个CSS风格

background-position: center center;

other options are 其他选择是

center top
center bottom
left top

etc... 等等...

There is just an onResize method used in Javascript so that when the browser changes then that changes the CSS for the background image's position. 在Javascript中只使用了一个onResize方法,这样当浏览器发生变化时,就会改变背景图像位置的CSS。

Give the image an id: id="fullImage" 为图像指定一个id: id="fullImage"

They then use javascript to manipulate the left:; 然后他们使用javascript来操纵left:; css style. css风格。

As you resize left changes up and down. 当您调整left变化时。

This should do it: 这应该这样做:

var el = document.getElementById(fullImage),
width = window.innerWidth,
imageWidth = [width of image here];
window.onresize = function() {
  el.style.left = imageWidth - width + "px";
}

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

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