首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过鼠标悬停切换打开,通过移出切换关闭,而不是单击

问通过鼠标悬停切换打开,通过移出切换关闭,而不是单击
EN

Stack Overflow用户
提问于 2012-06-20 14:19:26
回答 1查看 610关注 0票数 0

jQuery“切换”函数问题。

可以切换通过鼠标悬停启动的打开和通过鼠标移出的关闭,但不能通过单击...

目前的情况是:http://temp.wave-pr.com.hk/gbf/dock

如何通过鼠标悬停和鼠标移出来打开和关闭它?

js如下:

代码语言:javascript
复制
$(function () { 
// Stack initialize
var openspeed = 300;
var closespeed = 100;
$('.stack>img').toggle(function(){
    var vertical = 0;
    var horizontal = 0;
    var $el=$(this);
    $el.next().children().each(function(){
        $(this).animate({top: '-' + vertical + 'px', left: horizontal + 'px'}, openspeed);
        vertical = vertical + 55;
        horizontal = (horizontal+.75)*2;
    });
    $el.next().animate({top: '-50px', left: '10px'}, openspeed).addClass('openStack')
       .find('li a>img').animate({width: '50px', marginLeft: '9px'}, openspeed);
    $el.animate({paddingTop: '0'});
}, function(){
    //reverse above
    var $el=$(this);
    $el.next().removeClass('openStack').children('li').animate({top: '55px', left: '-10px'}, closespeed);
    $el.next().find('li a>img').animate({width: '79px', marginLeft: '0'}, closespeed);
    $el.animate({paddingTop: '35px'});
});
// Stacks additional animation
$('.stack li a').hover(function(){
    $("img",this).animate({width: '56px'}, 100);
    $("span",this).animate({marginRight: '10px'});
},function(){
    $("img",this).animate({width: '50px'}, 100);
    $("span",this).animate({marginRight: '0'});
});

});

EN

回答 1

Stack Overflow用户

发布于 2012-06-20 14:23:14

使用.hover函数代替.toggle。例如,

代码语言:javascript
复制
$('.stack>img').hover(function() {
    //previos was togle
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11113843

复制
相关文章

相似问题

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