English 中文(简体)
JQuery动画在锚点标记上不起作用
原标题:JQuery animation not working on anchor tag

当用户用鼠标悬停时,我使用easy插件来摇动我的锚点标签。如果我将其附加到<;之外的任何元素,它都会工作;a>标签。我还尝试将行为附加到前面的<;李>,但它在那里也不起作用。我是JQuery的合适人选;我想这一定是与锚点标签有关,但我在谷歌上快速搜索找不到任何东西。也许我忽略了什么?下面是我的代码:

          <section id="content">
              <nav>
                    <ul>
                        <li id="selected">Home</li>
                        <li style="margin-left:35px;"><a href="about_alabama_bunker.html" title="Learn about Alabama Bunker" class="shake">About</a></li>
                        <li style="margin-left:5px;"><a href="services_offered.html" title="Services offered by Alabama Bunker" class="shake">Services</a></li>
                        <li style="margin-left:5px;"><a href="security_bunker_products.html" title="Product catalog" class="shake">Products</a></li>
                        <li style="margin-left:25px;"><a href="contact_alabama_bunker.html" title="Get in touch with our sales staff for inquiries, comments or suggestions" class="shake">Contact</a></li>
                    </ul>
              </nav>

          </section>

我的JQuery:

<script type="text/javascript">
$(document).ready(function() {
$( a.shake ).hover(function(event) {
    $(this)
        .css(
            { color :  ff0000  }, {
                duration:  slow ,
                easing:  easeOutBounce 
            })
        .animate(
            { left: 25 }, {
                duration:  fast ,
                easing:  easeOutBounce 
            })
        .animate(
            { left: 0 }, {
                duration:  fast ,
                easing:  easeOutBounce 
            });
    });
});
</script>

更新

我删除了颜色更改的第一个动画。我尝试将类移动到<;导航><;ul>元素。我还确保了对选择器的调用是$(.shawk),而不是$$(a.shake)。任何情况下都没有工作人员。

最佳回答

在你的css中,你有属性position:relative还是place:absolute

nav ul li a.shake {
    text-decoration: none;
    display: block;
    position: relative;
    }


<script type="text/javascript">
    $(document).ready(function() {
    $( a.shake ).hover(function(event) {
        $(this)
            .animate(
                { left: 200 }, {
                    duration:  slow ,
                    easing:  easeOutBounce 
                })
            .animate(
                { left: 0 }, {
                    duration:  slow ,
                    easing:  easeOutBounce 
                });
    });
});
  </script>    

如果不添加position属性,它也无法与event.preventDefault()

我也希望你的<;头部>标签

<script src="yourPath/jquery.easing.1.3.js" type="text/javascript"></script>

这是工作所必需的。


因此,请按照以下方式编辑您的代码:

<section id="content">
              <nav>
                    <ul>
                        <li><a style="position: relative; margin-left:35px;" href="about_alabama_bunker.html" title="Learn about Alabama Bunker" class="shake">About</a></li>
                        <li><a style="position: relative; margin-left:5px;" href="services_offered.html" title="Services offered by Alabama Bunker" class="shake">Services</a></li>
                        <li><a style="position: relative; margin-left:5px;" href="security_bunker_products.html" title="Product catalog" class="shake">Products</a></li>
                        <li><a style="position: relative; margin-left:25px;" href="contact_alabama_bunker.html" title="Get in touch with our sales staff for inquiries, comments or suggestions" class="shake">Contact</a></li>
                    </ul>
              </nav>
          </section>

我测试了它,它奏效了!

问题回答

暂无回答




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...