Javascript或jQuery帮助 [英] Javascript or jQuery help

查看:75
本文介绍了Javascript或jQuery帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的网站: http://keironlowe.x10hosting.com/

我需要知道如何在悬停时让红线慢慢变长,然后使用javascript或jQuery慢慢收缩回正常大小。

I need to know how to make the red line slowly get longer when hovering over, and slowly shrink back to normal size afterwards using javascript or jQuery.

有人能告诉我一些正确的方向吗?

Could someone show me something to get started in the right direction?

推荐答案

你可以使用jQuery的动画对元素执行某些操作,其中包含一个duration参数,用于定义动画需要多长时间去完成。然后是 hover 功能一组功能。所以这是一般的想法:

You can use jQuery's animate to do something to an element, which includes a duration parameter that defines how long it should take for the animation to complete. Then there's the hover function which takes a set of functions. So this is the general idea:

$('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中/ code>:

As far as your comment, if the code is in the <HEAD>, you need to wrap the code in document.ready:

$(document).ready(function() {
    // put the code you tried here
});

这篇关于Javascript或jQuery帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆