【问题标题】:Javascript or jQuery help [closed]Javascript 或 jQuery 帮助 [关闭]
【发布时间】:2009-06-08 17:52:55
【问题描述】:

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

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

有人可以告诉我一些东西可以让我朝着正确的方向开始吗?

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    类似这样的:

    $('#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});}
    );
    

    【讨论】:

      【解决方案2】:

      您可以使用 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
      });
      

      【讨论】:

      • 我似乎无法正常工作。我有
      • 嗯,一开始就把那个
        拿掉
      • 它工作但我遇到了问题。当我将鼠标悬停在它上面时,我想增加大小,当我将光标移开时,它会恢复到正常大小但是代码使它增加,然后在悬停时恢复正常。它也只工作一次。我必须刷新它才能再次工作
      • 您是否在问题的 URL 上上传了代码?我必须在那里看到它才能进一步调试。
      • 在主页链接上也不起作用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      • 2020-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多