jQuery:使用一个函数在不同方向上对两个图像进行动画处理
我正在尝试使用单个函数来为两个不同的图像设置动画。我遇到的问题是其中一张图像需要为左侧属性设置动画,而另一张图像需要为右侧属性设置动画。我尝试了一些不同的事情,但据我所知:
$(document).ready(function(){
var puppy = $('.puppy'),
woman = $('.woman-smiling');
fadeImages(puppy, "left");
fadeImages(woman, "right");
});
function fadeImages($image, $direction){
$image.delay(500)
.css({
visibility: "visible",
display: "none"
}).animate({
opacity: "show",
$direction: "0px"
}, 1750);
}
延迟和衰落工作正常,但方向是混乱的。蒂亚!!!
I'm attempting to use a single function to animate two different images. The issue I'm having is that one of the images needs to animate the left attribute and the other needs to animate the right. I attempted a few different things, but this is as far as I got:
$(document).ready(function(){
var puppy = $('.puppy'),
woman = $('.woman-smiling');
fadeImages(puppy, "left");
fadeImages(woman, "right");
});
function fadeImages($image, $direction){
$image.delay(500)
.css({
visibility: "visible",
display: "none"
}).animate({
opacity: "show",
$direction: "0px"
}, 1750);
}
The delay and fading work fine, but the direction is what's messed up. TIA!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不能像现在一样使用 $direction 。也许这会起作用:
I don't think you can use $direction like you are doing. Perhaps this would work:
试试这个:
您所拥有的不起作用,因为在这种情况下它使用
$direction
作为 KEY,而不是用它替换变量的值。Try this:
What you have is not working because it is using
$direction
as a KEY in that case, and not substituting it for your variable's value.