【问题标题】:Toggle open by mouseover and close by moveout, not by a click通过鼠标悬停切换打开并通过移动关闭,而不是单击
【发布时间】:2012-06-20 06:19:26
【问题描述】:

jQuery“切换”功能问题。

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

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

如何通过 mouseover 和 mouseout 使其打开和关闭?

js如下:

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

});

【问题讨论】:

  • 然后用hover()代替toggle()...

标签: javascript jquery stack toggle


【解决方案1】:

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

$('.stack>img').hover(function() {
    //previos was togle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-25
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-03
    • 2012-03-13
    • 1970-01-01
    相关资源
    最近更新 更多