Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用纯CSS移动div元素的背景图像_Css_Jquery Animate_Background Image_Keyframe - Fatal编程技术网

使用纯CSS移动div元素的背景图像

使用纯CSS移动div元素的背景图像,css,jquery-animate,background-image,keyframe,Css,Jquery Animate,Background Image,Keyframe,我试图用纯CSS移动div元素的背景图像。在这里,我从用户那里输入背景图像url,这就是为什么我不能在CSS中声明它。我也不能将它声明为位置固定或绝对的图像,因为它会影响CSS的其余部分。有没有办法只为div元素的背景编写CSS 小提琴- HTML: 您需要做的是添加背景位置:x,y,其中x和y等于要定位元素的位置的长度和高度 根据AnandTech的一份新报告,三星可能会撒小谎以获得更有利的Galaxy S4基准。您的设备是否突然出现爬行?当然没有;基准测试不应该改变你对像S4一样强大的旗舰

我试图用纯CSS移动div元素的背景图像。在这里,我从用户那里输入背景图像url,这就是为什么我不能在CSS中声明它。我也不能将它声明为位置固定或绝对的图像,因为它会影响CSS的其余部分。有没有办法只为div元素的背景编写CSS

小提琴-

HTML:


您需要做的是添加背景位置:x,y,其中x和y等于要定位元素的位置的长度和高度


根据AnandTech的一份新报告,三星可能会撒小谎以获得更有利的Galaxy S4基准。您的设备是否突然出现爬行?当然没有;基准测试不应该改变你对像S4一样强大的旗舰的看法。不过,令人尴尬的是,三星会采取这样的技术策略,比如据称使用了名为“BenchmarkBooster”的代码。

您需要做的是添加背景位置:x,y,其中x和y等于要定位元素的位置的长度和高度


根据AnandTech的一份新报告,三星可能会撒小谎以获得更有利的Galaxy S4基准。您的设备是否突然出现爬行?当然没有;基准测试不应该改变你对像S4一样强大的旗舰的看法。不过,令人尴尬的是,三星会采取这样的技术策略,比如据称使用了名为“BenchmarkBooster”的代码。

以下技巧似乎有效:使背景图像的宽度为元素的两倍,并将背景位置的水平部分从0更改为
-200%
():


当背景位置为负百分比时,移动图像的算法得到了很好的解释。

以下技巧似乎有效:使背景图像的宽度为元素的两倍,并将背景位置的水平部分从0更改为
-200%
():


背景位置
为负百分比时移动图像的算法解释得很好。

谢谢。效果很好。有没有办法不将图像拉伸到200%并循环动画?谢谢。效果很好。是否有任何方法可以循环,而不将图像拉伸到200%并循环动画?
<div class="view" style="background-image: url('http://css3slideshow.remabledesigns.com/1.jpg')">According to a new report from AnandTech, Samsung might be fibbing its way to more favorable Galaxy S4 benchmarks. Has your device suddenly come to a crawl? Of course it hasn’t; benchmarks shouldn’t change your perception of a flagship as powerful as the S4. Still, it’s embarrassing that Samsung would resort to such technical tactics, like allegedly using code dubbed “BenchmarkBooster.” Yes, your device takes steroids.</div>
.view {
    position:relative;
    height:100%;
    width:100%;
    top:0;
    left:0;
    animation:mymove 5s infinite;
    -webkit-animation:mymove 5s infinite;
    /* Safari and Chrome */
}
@keyframes mymove {
     from {
         left:0px;
     }
     to {
         left:200px;
     }
}
@-webkit-keyframes mymove
/* Safari and Chrome */
    {
     from {
          leftp:0px;
     }
     to {
         left:200px;
     }
}
<div class="view" style="background-image: url('http://css3slideshow.remabledesigns.com/1.jpg') background-position:50px 20px;">
 According to a new report from AnandTech, Samsung might be fibbing its way to more favorable Galaxy S4 benchmarks. Has your device suddenly come to a crawl? Of course it hasn’t; benchmarks shouldn’t change your perception of a flagship as powerful as the S4. Still, it’s embarrassing that Samsung would resort to such technical tactics, like allegedly using code dubbed “BenchmarkBooster.” Yes, your device takes steroids.</div>
.view {
    height:100%;
    width:100%;
    animation:mymove 5s linear infinite;
    background-size: 200% 100%; /* horizontal scale is 200% */
}
@keyframes mymove {
    from {
        background-position: 0% 0px;
    }
    to {
        background-position: -200% 0px; /* shifting the image to right by its full width */
    }
}