埃米尔.js和徐动画需要双击

emile.js and xui animation needing double click?

本文关键字:双击 动画 js 徐动画 埃米尔      更新时间:2023-09-26

我正在使用 xui 和 emile 制作可折叠面板,但第一次单击需要双击,然后所有未来的单击都可以正常工作。我需要第一次单击才能单击。我还需要最初为那些非javascript用户隐藏带有javascript的列表。

谁能看出我哪里出错了?

这是我扩展徐

的地方

xui.extend ( {

 togglePanel:function(dur,thePanel)
 {
    var panel = document.getElementById(thePanel);
    var theHeight =  document.getElementById(thePanel).scrollHeight;

        if(panel.closed){
        emile(panel, 'height:'+theHeight+'px',{duration:dur});
        panel.closed = false;
        }
        else{
        emile(panel, 'height:0px', {duration:dur});
        panel.closed = true;
        }
    }
});

这是面板的调用和隐藏

  x$(window).load(function(e){
                        emile('item', 'height:0px', {duration:-0});
                        x$('.panel a.panelItem').click(function(e){
          x$().togglePanel(900,'item');})
        });

我也试过

x$('#item')setStyle ('height','0px');

以隐藏内容。

我知道了。还从埃米尔的叉子上切下了一些补间功能

徐扩展

    xui.extend (
    {
     togglePanel:function(dur,thePanel)
     {
          if (dur === "slow"){
             dur = 1500;
         }
         else if (dur === "fast"){
             dur = 500;
         }

        var panel = document.getElementById(thePanel);
        var theHeight =  document.getElementById(thePanel).scrollHeight;
            if(x$(this).hasClass('closed')){
            emile(panel, 'height:'+theHeight+'px',{duration:dur,easing:bounce, after: function() {
           x$(panel).removeClass('closed');
}});
            }            
            else {
            emile(panel, 'height:0px', {duration:dur,easing:easeInStrong, after: function() {
            x$(panel).addClass('closed');    
}});
            }

        }
    });

初始化

    x$(window).load(function(e){
     x$('#item').addClass('closed');    
x$('.panel a.panelItem').click(function(e){
    x$('#item').togglePanel('slow','item');})
      });

以及 https://github.com/ded/emile 的一些额外的补间方法

      function easeOut (pos) {
    return Math.sin(pos * Math.PI / 2);
  };
  function easeOutStrong (pos) {
    return (pos == 1) ? 1 : 1 - Math.pow(2, -10 * pos);
  };
  function easeIn (pos) {
    return pos * pos;
  };
   function easeInStrong(pos) {
    return (pos == 0) ? 0 : Math.pow(2, 10 * (pos - 1));
  };
                function bounce(pos) {
    if (pos < (1/2.75)) {
        return (7.5625*pos*pos);
    } else if (pos < (2/2.75)) {
        return (7.5625*(pos-=(1.5/2.75))*pos + .75);
    } else if (pos < (2.5/2.75)) {
        return (7.5625*(pos-=(2.25/2.75))*pos + .9375);
    } else {
        return (7.5625*(pos-=(2.625/2.75))*pos + .984375);
    }
  };

仍然需要改进它,但我们正在到达那里。