如何改善网站标题的滑动效果?
这就是我在这个页面上制作滑动效果的方法: dmg-01.net:
$(document).ready(function(){
$(".trail-text").attr("style", "display:none;");
if ($("#one,#two,#three,#four,#five")) {
var pixies = $("#one,#two,#three,#four,#five");
$("#one,#two,#three,#four,#five").hover( function() {
$(this).find(".trail-text").slideDown("fast");
}, function() {
$(this).find(".trail-text").slideUp("fast");
});
};
});
我想改进它,因为它没有我想要的那么优雅。我认为如果同时只出现一张幻灯片效果而不重叠会更好。
另一方面,我尝试以这种方式实现相同的效果:
$(function(){
$("#one,#two,#three,#four,#five").each(function(){
$(this).hover(function(){
$(this).animate({height: "100%", width: "100%"}, {queue:false, duration:111});
},function() {
$(this).animate({height: "44px", width: "44px"}, {queue:false, duration:333});
});
});
});
我放弃了它,因为我不知道如何设置高度“auto”,并且“隐藏”元素内的内容在元素外部可见。
如何改进?
根据我的目的,我更喜欢使用 CSS 属性为元素的后代设置动画。这就是我尝试做的方法,但它不起作用。为什么?
$(document).ready(function(){
$(".trail-text").attr("style", "display:none;");
if ($(".#one,#two,#three,#four,#five")) {
$("#one,#two,#three,#four,#five").hover(
function() { $(this).find(".trail-text").animate({height: "100%", width: "444px"}, {queue:false, duration:111}); },
function() { $(this).find(".trail-text").animate({height: "0", width: "444px"}, {queue:false, duration:333}); }
);
};
});
This is how I made the sliding effect on this page: dmg-01.net:
$(document).ready(function(){
$(".trail-text").attr("style", "display:none;");
if ($("#one,#two,#three,#four,#five")) {
var pixies = $("#one,#two,#three,#four,#five");
$("#one,#two,#three,#four,#five").hover( function() {
$(this).find(".trail-text").slideDown("fast");
}, function() {
$(this).find(".trail-text").slideUp("fast");
});
};
});
I would like to improve it because it's not as graceful as I want. I think it would be better if only one slide effect occur at the same time with no overlapping.
On the other hand, I tried to accomplish the same effect this way:
$(function(){
$("#one,#two,#three,#four,#five").each(function(){
$(this).hover(function(){
$(this).animate({height: "100%", width: "100%"}, {queue:false, duration:111});
},function() {
$(this).animate({height: "44px", width: "44px"}, {queue:false, duration:333});
});
});
});
I discarded it because I don't know how to set "auto" for height and the content inside the "hidden" elements are visible outside the element.
How can this be improved?
According to my purpose, I prefer to animate with CSS properties the descendants of the elements. This is how I tried to do it but it isn't working. Why?
$(document).ready(function(){
$(".trail-text").attr("style", "display:none;");
if ($(".#one,#two,#three,#four,#five")) {
$("#one,#two,#three,#four,#five").hover(
function() { $(this).find(".trail-text").animate({height: "100%", width: "444px"}, {queue:false, duration:111}); },
function() { $(this).find(".trail-text").animate({height: "0", width: "444px"}, {queue:false, duration:333}); }
);
};
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 jQuery“queue" 方法来链接动画。
Use jQuery "queue" method to chain the animations.
所以你可以跳过一个额外的循环
So you can skip an additional loop
最后,我用这个技巧改进了效果。
不过,我更喜欢
.animate
而不是.slideDown/Up
,这样我就可以添加 CSS 属性。无论如何,动画很流畅,我很满意。感谢您的建议和改进!Finally, I improve the effect with this trick.
However, I would have preferred
.animate
instead of.slideDown/Up
so I can add CSS properties. Anyway, the animation is smooth and I'm satisfied. Thank you for your advice and improvements!