【发布时间】:2009-06-08 17:52:55
【问题描述】:
这是我的网站:http://keironlowe.x10hosting.com/
我需要知道如何让红线在悬停时慢慢变长,然后使用javascript或jQuery慢慢缩小到正常大小。
有人可以告诉我一些东西可以让我朝着正确的方向开始吗?
【问题讨论】:
标签: javascript jquery
这是我的网站:http://keironlowe.x10hosting.com/
我需要知道如何让红线在悬停时慢慢变长,然后使用javascript或jQuery慢慢缩小到正常大小。
有人可以告诉我一些东西可以让我朝着正确的方向开始吗?
【问题讨论】:
标签: javascript jquery
类似这样的:
$('#nav_container div').hover(
function(){$(this).find('img').animate({width:'100%'},{queue:false,duration:500});},
function(){$(this).find('img').animate({width:'auto'},{queue:false,duration:500});}
);
【讨论】:
您可以使用 jQuery 的 animate 对元素执行某些操作,其中包含一个持续时间参数,该参数定义动画完成所需的时间。然后是hover 函数,它采用一组函数。所以这是一般的想法:
$('div', '#nav_container').hover(function() {
// this gets called on hover
$(this).animate({width: 'XXXpx'}, 10000); // 10000 = 10 seconds
}, function() {
// this gets called on mouseout
$(this).animate({width: 'XXXpx'}, 10000); // 10000 = 10 seconds
});
编辑:
就您的评论而言,如果代码在<HEAD>中,则需要将代码包装在document.ready中:
$(document).ready(function() {
// put the code you tried here
});
【讨论】: