简单的 jQuery 动画
我已经发布了类似的问题但没有回复。
我有一个 jQuery Mobile 网站,我需要在标题中添加一个简单的动画。
在这里查看我的JSfiddle: http://jsfiddle.net/motocomdigital/twGHC/39/
我我的标题中有一个徽标,宽度为:284px; height:58px; 这是一个 1px 透明 GIF - 被背景图像替换。
我的背景图像包含两张需要循环淡入淡出的幻灯片。
我需要徽标在图像上的这 2 个 css 规则之间循环(淡入/淡出):
div#header-logo a img {
background-position: top;
}
我
div#header-logo a img {
background-position: bottom;
}
认为 jquery css 属性是 {backgroundPosition, 'bottom' }
和 {backgroundPosition, 'top' }
每张幻灯片在循环之前可以显示 2 秒。
有人可以告诉我仅使用 jQuery Mobile 是否可以实现这一点?并且不必引入新的插件。尝试通过函数使其尽可能轻便。
任何帮助都会非常感谢!
我的 HTML
<div id="header-logo">
<a href="#home" data-direction="reverse">
<img src="x.gif" alt="" style="width:284px;height:58px;" />
</a>
</div>
我的 CSS
div#header-logo {
bottom: 0;
position: relative;
margin: 14px auto 0;
padding: 0;
width: 282px;
height: 73px;
}
div#header-logo a img {
width: 284px;
height: 58px;
background-image: url('http://www.freeimagehosting.net/newuploads/85137.png');
background-size: 100% 200%;
background-position: top;
background-color: red;
}
如果您想体验,请参阅我的 JSfiddle... http://jsfiddle.net/ motocomdigital/twGHC/39/
更新:第一个想法似乎工作正常,谢谢安迪!看这里.. http://jsfiddle.net/motocomdigital/twGHC/40/
可以吗有打火机吗?
I've posted similar question but no response.
I have a jQuery Mobile site and I need a simple animation in my header.
See my JSfiddle here: http://jsfiddle.net/motocomdigital/twGHC/39/
I have a logo in my header which is width:284px; height:58px;
and it's a 1px Transparent GIF - being replaced with a background image.
My background image contains the two slides that I need a cycle fade on.
I need the logo to cycle (fade in/out) between these 2 css rules on my image:
div#header-logo a img {
background-position: top;
}
and
div#header-logo a img {
background-position: bottom;
}
I think the jquery css property is { backgroundPosition, 'bottom' }
and { backgroundPosition, 'top' }
Each slide can be shown for 2seconds before cycling.
Can someone tell me if this is possible just using jQuery Mobile? and not having to introduce a new plugin. Trying to keep this as light as possible with a function.
Any help would be amazing thanks!
My HTML
<div id="header-logo">
<a href="#home" data-direction="reverse">
<img src="x.gif" alt="" style="width:284px;height:58px;" />
</a>
</div>
My CSS
div#header-logo {
bottom: 0;
position: relative;
margin: 14px auto 0;
padding: 0;
width: 282px;
height: 73px;
}
div#header-logo a img {
width: 284px;
height: 58px;
background-image: url('http://www.freeimagehosting.net/newuploads/85137.png');
background-size: 100% 200%;
background-position: top;
background-color: red;
}
See my JSfiddle here if you want to experiement... http://jsfiddle.net/motocomdigital/twGHC/39/
UPDATE: First idea seems to work fine, thanks Andy! See here.. http://jsfiddle.net/motocomdigital/twGHC/40/
Can it get any lighter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如何定位图像的克隆,将克隆设置为
background-position: Bottom
,然后将 2 秒的间隔设置为.animate()
每个图像的不透明度
?可能不是最干净的方法,但将此代码放入您的小提琴中对我来说在 Chrome 14 中有效,无需任何其他 CSS 或 HTML 更改。How about positioning a clone of the image, with the clone having
background-position: bottom
set and then a 2 second interval to.animate()
theopacity
of each image? Might not be the cleanest way to do it but dropping this code into your fiddle works for me in Chrome 14 without any other CSS or HTML changes.