简体   繁体   English

使用CSS repeat-x重复多个图像

[英]Repeating multiple images with CSS repeat-x

I'm making a UHD project that requires displaying huge images. 我正在制作一个需要显示巨大图像的UHD项目。 There's no problem with stationary browsers however iOS and some mobile browsers are very limited in that field. 固定浏览器没有问题,但iOS和某些移动浏览器在该领域非常有限。 The max resolution for iOS PNG is 5 megapixels which is far lower than most of the images that I need to display. iOS PNG的最大分辨率为5百万像素,远远低于我需要显示的大部分图像。

Jpeg and other formats are not an option. Jpeg和其他格式不是一种选择。

So far I decided to split big images into smaller ones and I've encountered a problem. 到目前为止,我决定将大图像分成较小的图像,我遇到了一个问题。 I've created a fiddle to show what's going on. 我创造了一个小提琴来展示正在发生的事情。

JSFIDDLE 的jsfiddle

As you can see I used 2 images in "background-image" to show the exact problem. 如您所见,我在“background-image”中使用了2个图像来显示确切的问题。 The first image (circle) appears on top of the second (square). 第一个图像(圆圈)出现在第二个(正方形)的顶部。

Here is the code for CSS: 这是CSS的代码:

    <style type="text/css">
        html {
        overflow-x: hidden;
        }
        html, body { height: 100%; width: 100%;}
              body { overflow-x: hidden;
              background-image: url('http://www.clipartbest.com/download?clipart=di7eRd49T'), url('http://i126.photobucket.com/albums/p89/robertthomas_2006/600x600.png');
          background-repeat: repeat-x, repeat-x;
              background-position: left, right;
              }

And jQuery: 和jQuery:

    $(function(){
        var x = 0;
        setInterval(function(){
        x-=1;
        $('body').css('background-position', x + 'px 0');
    }, 10);
    });

So the problem is that both "small" images are not side by side. 所以问题在于两个“小”图像并不是并排的。 There's no problem if I stitch them back in 1 big image. 如果我将它们拼接成一张大图像就没问题了。 However mobile devices cannot handle it. 但移动设备无法处理它。

As far as I can see the "background-postion" in my css is ignored for some reason. 据我所知,我的CSS中的“背景位置”由于某种原因被忽略了。

SO is there a way to apply "background-repeat: repeat-x" to the whole block of background images and put images side by side? 那么有没有办法将“background-repeat:repeat-x”应用于整个背景图像块并将图像并排放置?

I need from 2 to 10 background images to be repeated as the "organic whole" at the same time. 我需要从2到10个背景图像同时作为“有机整体”重复。

Is it possible with the method I'm using? 我用的方法有可能吗? If not - what is the best solution? 如果不是 - 什么是最好的解决方案?

Well the background property is not in any way comfortable for doing what you want to do. 那么背景属性对于做你想做的事情并不是很舒服。 I advice you then to place the images in a div, which div in other hand could be displayed below the other content (with position absolute), so it acts as a background. 我建议你把图像放在一个div中,另一只手中的div可以显示在其他内容下面(绝对位置),因此它可以作为背景。 Note that you have to set z-index to your content also, and it should be a higher number than the z-index of your "background" div. 请注意,您还必须将z-index设置为您的内容,并且它应该是比“background”div的z-index更高的数字。 Again I advice you not to repeat the whole set of images endlessly, but rather start the animation again when it reaches the last one. 我再次建议你不要无休止地重复整个图像集,而是在它到达最后一个时再次启动动画。 Give me a comment if you need a deeper explanation of something form above. 如果您需要对上述内容进行更深入的解释,请给我评论。

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

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