Ken Burns 与 CSS 3 - 它有多难
使用 CSS3 我认为基于 CSS 的 Ken Burns 效果没有理由不起作用。我的第一次尝试涉及使用 Jquery 将新类添加到背景图像。
.flare1 {
background-position:-50.1px -50.1px !important;
-webkit-transition: all 5s ease-in-out;
}
function gallery() {
$('.cornerimg').addClass('flare1');
}
这有效,但非常不稳定。所以我正在考虑采用不同的方法。如果从一开始就给图像设置一个类动画会怎么样?我不熟悉 CSS3 动画,只熟悉过渡,但目的是将永久类应用于一系列图像,使它们始终顺利地呈现给 Ken Burn。
我为任何想尝试的人准备了一个可爱的试验场。 http://jsfiddle.net/gxUhH/10/
全部根据我的初始代码进行设置。
有什么想法吗?
很棒的
编辑——
好吧,我发现这看起来非常顺利。我看不出它有什么不同。他们正在使用 web-kit 中的翻译功能,但当我尝试时,它就跳了。看看吧。 http://thing13.net/2010/02/css3-ken-烧伤效果-2/
Working with CSS3 I see no reason why a CSS based Ken burns effect would not work. My first attempt involved using Jquery to add a new class to a background image.
.flare1 {
background-position:-50.1px -50.1px !important;
-webkit-transition: all 5s ease-in-out;
}
function gallery() {
$('.cornerimg').addClass('flare1');
}
This worked but is frightfully jerky. So I am considering a different approach. How would it be if the images were set with a class animation from the beginning. I am not familiar with the CSS3 animations, only the transitions, however the purpose being to apply a permanent class to a series of images that caused them to Ken Burn smoothly all the time.
I have prepared a lovely testing ground for anyone fancying a go.
http://jsfiddle.net/gxUhH/10/
All set up based on my initial code.
Any ideas?
Marvellous
EDIT --
Well chaps I found this that appears to be very smooth. What I cannot see is what about it is different. They are using the translate function in web-kit instead but when I tried that it just jumped. Take a look. http://thing13.net/2010/02/css3-ken-burns-effect-2/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的动作很不稳定,因为您一次只能将背景移动至少 1 个像素。您可以通过将
background-position
设置为 10px 并将过渡时间设置为10s Linear
来测试这一点,您会看到图像每秒移动一次像素。一个像素听起来可能不多,但当你缓慢移动时,它是相当明显的。
我的解决方案是更快地移动图像。至少每秒 20 像素是流畅运动的最低速度。
遗憾的是,在浏览器实现硬件加速之前,您可能无法对背景图像进行实时子像素重采样。
Your motion is jerky because you can only move the background by a minimum of 1 pixel at a time. You can test this by setting the
background-position
to 10px and the transition time to10s linear
, and you'll see that once per second the image shifts by exactly one pixel.One pixel might not sound like much, but when you're moving slowly it's quite noticeable.
My solution would be to move the image more quickly. At least 20 pixels per second would be the the minimum speed for smooth-looking motion.
Sadly until browsers implement hardware acceleration, you probably won't be getting real-time sub-pixel resampling on background images.
你可以为你的 CSS 做这样的事情。 (根据需要自定义)
http://jsfiddle.net/gxUhH/23/
You could do something like this for your CSS. (Customize as needed)
http://jsfiddle.net/gxUhH/23/
我尝试使用 protofunc 中的代码进行快速破解,该代码使用 backgroundPosition jQuery 插件。该插件可让您控制背景位置,例如:
我将一个巨大的 JPG 作为背景图像放在一个小 div 上。然后,可以通过单击触发动画,或通过回调事件堆叠动画,以及 jQuery 可以执行的所有常用操作。它在我的机器上的 Chrome 中运行得非常流畅。
重新阅读你的问题后,它不使用 CSS3...所以不是一个非常有用的答案! :P
I tried a quick hack with the code from protofunc which uses a backgroundPosition jQuery plugin. The plugin lets you control background position like:
I put a giant JPG as a background image on a small div. Then animations can be triggered by clicking, or stacked through callback events, and all the usual stuff jQuery can do. And it runs real smooth in Chrome on my machine.
After re-reading your question it doesn't use CSS3 though... so not a very helpful answer! :P
好吧,伙计们不会问我怎么做,但通过关键帧动画现在很流畅。
http://jsfiddle.net/gxUhH/47/
不过只有一个问题。当人们在触摸屏设备上滚动时,页面会变得不稳定。我认为我们需要在滚动时暂停它,然后在滚动完成后再次播放。
有什么想法吗?
Well chaps do not ask me how but via keyframe animation it is now smooth.
http://jsfiddle.net/gxUhH/47/
Just one problem though. When one scrolls on a touchscreen device the page it them becomes jerky. I think we need to pause it on scroll and then play again once the scrolling has finished.
Any ideas?