jquery - 滑动动画只有一个div

标签 jquery css animation this mouseover

我有一个小问题,我想创建一个幻灯片动画。你可以看到我的代码: click here .

但是正如您所见,当我们将鼠标“悬停”在一个 div 上时,所有的 div 都会动画化! 我想:当我们在一个 div 上“鼠标悬停”时,只有这个 div 是动画的,而不是其他的。

$(".button span").mouseover( function() {
$(this).stop().animate({ height:"+5%"}, 500);}); }); $(function() {

$(".button").mouseout( function(){
$(".button span").stop().animate({ height:"150px"}, 500);});

$(".button").mouseover( function(){
$(".button span").stop().animate({ height:"+5%"}, 500);});

感谢您宝贵的帮助。

最佳答案

您需要使用this 作为选择跨度的上下文:

http://jsfiddle.net/TKcSU/

$(function () {
    $(".button").mouseout(function () {
        $('span', this).stop().animate({
            height: "150px"
        }, 500);
    });

    $(".button").mouseover(function () {
        $('span', this).stop().animate({
            height: "+5%"
        }, 500);
    });
});

替代方案是 $(this).find('span')$(this).children('span');

关于jquery - 滑动动画只有一个div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18768187/

相关文章:

html - IE8 float 问题再次出现

html - CSS:是否可以在另一个字段集之前为一个字段集指定样式?

javascript - 使用 jquery 检查特定字符串的 url

jquery autoComplete 以 List<string> 作为源

javascript - $ ('#tabs a' ) 和 $ ('#tabs' ) 之间的差异。找到 ('a' )

javascript - 如何在jquery中获取随机元素?

html - 使用图像代替颜色作为侧边栏背景

css - 响应式 CSS3 链式动画、暂停和恢复问题

javascript - 如何用JS制作无限跑马灯?

Javascript - Buggy SlideToggle 效果(无 jQuery)