首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置链接后,jquery动画不起作用

问设置链接后,jquery动画不起作用
EN

Stack Overflow用户
提问于 2012-12-31 07:54:29
回答 1查看 160关注 0票数 0

我在一张图片上有一个JQUERY的悬停动画。另一张图片滑了出来。当图片没有链接到url时,它工作得很完美。当我在底部图像中添加标签时可以,但当我将标签添加到图像上时,动画不起作用。

下面是我的jquery代码:

代码语言:javascript
复制
<script type="text/javascript">
$(function() {
    $('.wrap').hover(function() {
        $(this).children('.front').stop().animate({ "top" : '-100px'}, 700);   
    }, function() {
        $(this).children('.front').stop().animate({ "top" : '0px'}, 400);       
    });
});

​

这是我的css和html代码

代码语言:javascript
复制
<style type="text/css">

#container {
height:100px;
text-align: center;
margin: auto;
}

.wrap {
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
float: left;
padding: 0 1em;
}

img {
position: relative;
top: 0px; left: 0px;
}
img.front {
position: relative;
top: 100px; 
}
body
{ 
background-image:url('bgimage.png');
background-repeat:no-repeat;
background-attachment:fixed;
background-position:right bottom; 
}
</style>
</head>


   <body>
 <div id="container">
<div class="wrap">
   <a href="ascolta.php"> <img src="radio.png" alt="image" /></a>
      **<a href="ascolta.php">** <img src="radio_h.png" class="front" alt="image" /></a>
 </div>
   <div class="wrap">
    <img src="chat.png" alt="image" />
    <img src="chat_h.png" class="front" alt="image" />
 </div>
   <div class="wrap">
    <img src="programms.png" alt="image" />
    <img src="programms_h.png" class="front" alt="image" />
 </div>
    <div class="wrap">
    <img src="gallery.png" alt="image" />
    <img src="gallery_h.png" class="front" alt="image" />
 </div>
</div>        

在代码中,当我添加星号标记时,相关的动画停止工作。

非常感谢。最好的

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-31 07:58:08

您使用的是.children,它只在DOM中向下移动一层。请改用.find。

更改此设置:

代码语言:javascript
复制
$(this).children('.front').stop().animate({ "top" : '-100px'}, 700);
$(this).children('.front').stop().animate({ "top" : '0px'}, 400); 

至

代码语言:javascript
复制
$(this).find('.front').stop().animate({ "top" : '-100px'}, 700);
$(this).find('.front').stop().animate({ "top" : '0px'}, 400); 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14095941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档