简体   繁体   English

如何清除背景图片溢出?

[英]How to remove background-image overflow?

I'm trying to remove the overflow from a background-image within a div. 我正在尝试从div中的背景图像中删除溢出。 I've got 4 divs with identical images that create one background image(I position each image so that it matches across the 4 divs). 我有4个具有相同图像的div,它们创建了一个背景图像(我将每个图像放置在4个div上,以使其匹配)。 Basically I'm trying to animate the "singular" image to the left and have another image replace it within the same animation(which is really just a css transition). 基本上,我试图为左侧的“奇异”图像设置动画,并在同一动画中替换另一幅图像(这实际上只是一个CSS过渡)。 The problem is that the overflow: hidden hides the overflow but when you move it to the left you get to see the rest of that hidden image. 问题在于溢出:隐藏隐藏了溢出,但是当您将其移到左侧时,您会看到该隐藏图像的其余部分。

Is there any way to clip or remove the overflow so that my transition will look like one image moving to the left? 有什么方法可以剪辑或消除溢出,以便过渡效果看起来像是向左移动一幅图像?

Css 的CSS

.changeOver{
background-repeat: no-repeat;
background-position:130% !important;
-webkit-transition:  2s;
-moz-transition:  2s;
-o-transition:  2s;
transition:  2s;}

The Script 剧本

$('#change').click(function () {
   $('#fourth').addClass('changeOver');
    setTimeout(function(){ 
        $('#fourth').css('background-image', 'none'); 
    }, 5000);
    setTimeout(function(){ 
        $('#fourth').css('background-color', 'blue'); 
    }, 1);

    setTimeout(function(){
    $('#third').addClass('changeOver');
    setTimeout(function(){ 
        $('#third').css('background-image', 'none'); 
    }, 5000);
    setTimeout(function(){ 
        $('#third').css('background-color', 'blue'); 
    }, 1);
    }, 2000);

    setTimeout(function(){
    $('#second').addClass('changeOver');
    setTimeout(function(){ 
        $('#second').css('background-image', 'none'); 
    }, 5000);
    setTimeout(function(){ 
        $('#second').css('background-color', 'blue'); 
    }, 1);
    }, 4000);

    setTimeout(function(){
    $('#first').addClass('changeOver');
    setTimeout(function(){ 
        $('#first').css('background-image', 'none'); 
    }, 2000);
    setTimeout(function(){ 
        $('#first').css('background-color', 'blue'); 
    }, 1);
    }, 6000);    
});

Edit: Here's the jsfiddle just click the button labeled 'yes' 编辑: 这是jsfiddle,只需单击标记为“是”的按钮

Edit: So, without redoing all your code, the problem is that you aren't moving the divs themselves. 编辑:因此,在不重做所有代码的情况下,问题在于您没有移动div本身。

Put {outline: 1 px solid red;} in them and you'll see that they don't actually move, which is why you're scrolling through the background. 将{outline:1 px实心红色;}放入其中,您会看到它们实际上并没有移动,这就是您在背景中滚动的原因。 Hiding your overflow doesn't actually help unless you're moving the divs themselves, which you aren't. 除非您自己移动div,否则隐藏溢出实际上并没有帮助。

You could alter the image so that whatever you want beneath it is already on it. 您可以更改图像,以便其下方所需的任何内容都已经在其上。 So, the overflow is actually a different image, but they'd be the same file. 因此,溢出实际上是不同的图像,但是它们将是相同的文件。

So, something like |main image|next image| 因此,类似|主图像|下一个图像| all attached. 全部附上。 That would make it look like the image is being pulled in. 那会使它看起来像是在拉入图像。

If you want more of a static reveal, you would have to create four images with transparencies where the overflow would be. 如果要更多的静态显示,则必须创建四张具有透明胶片的图像,而这些透明胶片将是溢出的。

It's very easy and you can even do it online with pxlr. 这非常容易,您甚至可以使用pxlr在线进行。

Otherwise, you have to animate actual divs and not just 否则,您必须为实际的div设置动画,而不仅仅是

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

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