寻找 jQuery 效果来逐渐显示隐藏的 DIV/图像
可能我错过了一些明显的东西,但我无法弄清楚如何慢慢地显示隐藏的图像/DIV,以便它从上到下显示。
如果你看一下这个 jsfiddle,你会看到我试图在 jQuery 中使用“show”来显示的图像:
http://jsfiddle.net/nickharambee/Lj7z9/13/
“show”的问题在于它从左上角开始增长图像。
我正在寻找的是希望从这些图像中可以清楚地看到的效果:
<图片src="https://i.sstatic.net/pN1ss.png" alt="在此处输入图像描述">
即红色“主页”图像/DIV 从上到下逐渐显示,以便覆盖棕色“主页”图像。
是否有可能用 jQuery 实现这样的效果,如果可以的话最好的方法是什么?我想在导航栏中的所有图像上使用此过渡。
谢谢,
尼克
添加代码
HTML:
<li id="test2"><img src="images/home3.png"></li>
CSS:
li {
background: url('images/sprite.png') no-repeat;
background-position: 0px 0px;
height: 40px;
}
脚本:
$("li#test2").hover(
function () {
$(this).animate({
'background-position-y': '-40'
}, 500);
},
function () {
$(this).animate({
'background-position-y': '0'
}, 500);
}
);
It may be that I am missing something obvious, but I can't work out how to reveal a hidden image/DIV slowly, so that it is shown from top to bottom.
If you look at this jsfiddle you will see the image that I am trying to reveal using 'show' in jQuery:
http://jsfiddle.net/nickharambee/Lj7z9/13/
The trouble with 'show' is that it grows the image from top left.
What I am looking for is an effect that hopefully is clear from these images:
i.e. the red 'home' image/DIV is gradually revealed from top to bottom so that it overlays the brown 'home' image.
Is it possible to achieve an effect like this with jQuery and if so what would be the best method? I am wanting to use this transition on all of the images in my nav bar.
Thanks,
Nick
ADDED CODE
HTML:
<li id="test2"><img src="images/home3.png"></li>
CSS:
li {
background: url('images/sprite.png') no-repeat;
background-position: 0px 0px;
height: 40px;
}
SCRIPT:
$("li#test2").hover(
function () {
$(this).animate({
'background-position-y': '-40'
}, 500);
},
function () {
$(this).animate({
'background-position-y': '0'
}, 500);
}
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将悬停图像放入具有此样式类的 div 中:
这会使图像不可见,因为其容器(div)高度为零,并且其溢出(整个图像)被隐藏。
然后像这样设置 div.blind 动画:
现在图像的容器对于整个悬停图像来说已经足够大了。悬停图像从上到下逐渐显示。
我的工作地点是: http://jsfiddle.net/cHt8V/1/
Put the hover image in a div that has this style class:
That makes the image invisible because its container (the div) is zero-height and its overflow (the whole image) is hidden.
Then animate div.blind like so:
Now the image's container is big enough for the whole hover image. The hover image is gradually revealed, from top to bottom.
I have this working at: http://jsfiddle.net/cHt8V/1/
为了避免这些 jquery 动画方法闪烁,我将对“悬停”外观的容器的高度进行动画处理,如下所示:
http://jsfiddle.net/Lj7z9/16/
To avoid these jquery animation method flickers I'd animate the height of a container of the "hover" look, like so:
http://jsfiddle.net/Lj7z9/16/
您可以通过在 jQuery 中使用
slideDown('slow')
动画来实现此目的。您可以使用
slow
或fast
或normal
作为参数来控制速度。更新了小提琴:http://jsfiddle.net/Lj7z9/14/
you can achieve this by using
slideDown('slow')
in jQuery for animation.You can control speed by using
slow
orfast
ornormal
as parameter.updated the fiddle : http://jsfiddle.net/Lj7z9/14/
我只能想到两种方法来做到这一点,一种是创建动画图像(您不想要)。
另一种方式的灵感来自 youlove.us 的旧主页(他们使用具有透明度的白色 png,并从背景中“剪出”字样。这是分层在不断滚动的彩色背景上的。)
您可以通过使用 3 来适应这一点具有绝对定位和合适的 z-index 值的 div 可以将它们放在另一个之上:
底部有灰色背景
顶部是一张图像,其中“家”一词被剪掉,因此灰色显示出来
中间是您要设置动画的...创建一个具有红色背景的div,并使用toggle()(或者如果您愿意的话可以向上滑动和向下滑动)对其进行动画设置
我希望这有意义吗?
There are only 2 ways I can think of to do this, and one is creating an animated image (which you don't want).
The other way is inspired by youlove.us's old homepage (they used a white png with transparency, with the words "cut out" from the background. This was layered over a coloured background that constantly scrolled.)
You could adapt this by using 3 divs with absolute positioning and suitable z-index values to place them on top of one another:
the bottom has a grey background
the top is an image with the word "home" cut out so the grey shows through
the middle is the one that you will animate... create a div with red background and animate it using toggle() (or slideup & slidedown if you prefer)
I hope this makes sense?