emile.js and xui animation needing double click?

我怕爱的太早我们不能终老 提交于 2019-12-12 05:17:41

问题


I am using xui and emile to make a collapsible panel but the first click needs a double click then all future clicks works fine on single click. I need the first click to work on single click. I also need to initially hide the list with javascript for those non javascript users.

Can anyone see where I have gone wrong?

Here is where I have extended xui

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;
        }
    }
});

And this is the call and the hiding of the panel

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

        });

I have also tried

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

to hide the content.


回答1:


I have got it. Also nicked a few tweening functions from a fork of emile

xui extended

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


        }
    });

The initialisation

    x$(window).load(function(e){
     x$('#item').addClass('closed');    

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

and some extra tweening methods from 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);
    }
  };

Still need to improve it a bit but we are getting there.



来源:https://stackoverflow.com/questions/10130486/emile-js-and-xui-animation-needing-double-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!