views:

52

answers:

3

Hello. I have a panel that fades images in and out. However, the first image fades completely out before the second image fades in. I would like them to be fading at the same time.

I'm using a Spry effect because I'm not too familiar with Javascript, but here's what I have.

In my HTML:

<script type="text/javascript">
var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", { interval: 3000 });
TabbedPanels1.start();
</script>

And in my Javascript effects script (there's also the main tabbed panels js, but it's not relevant):

Spry.Widget.TabbedPanels.prototype.fadeInNextPanel = function()
{
    if (!Spry.Effect || !Spry.Effect.DoFade)
    {
        // The fade effect isn't available, so just
        // show the next panel.

        this.showNextPanel();
        if (this.timerID)
            this.start();
        return;
    }

    var curIndex = this.getCurrentTabIndex();
    var panels = this.getContentPanels();
    var currentPanel = panels[ curIndex ];
    var nextPanel = panels[ (curIndex + 1) % this.getTabbedPanelCount() ];
    var self = this;

Spry.Effect.DoFade(currentPanel, {duration: 1000, from: 100, to: 0, toggle: false, finish: function()
    {
        nextPanel.style.opacity = '0';
        nextPanel.style.filter = 'alpha(opacity=0)';

        self.showPanel(nextPanel);

        currentPanel.style.opacity = '';
        currentPanel.style.filter = '';
        Spry.Effect.DoFade(nextPanel, {duration: 1000, from: 0, to: 100, toggle: false, finish: function()
        {
            if (self.timerID)
                self.start();
        }});
    }});

I can see that it's saying when the fade out finishes, start the fade in. But I don't know how to change it so that they happen at the same time.

Thank you.

A: 

Try something like this:

nextPanel.style.opacity = '0';
nextPanel.style.filter = 'alpha(opacity=0)';
self.showPanel(nextPanel);

Spry.Effect.DoFade(currentPanel, {
  duration: 1000, 
  from: 100, 
  to: 0, 
  toggle: false, 
  finish: function() {
      currentPanel.style.opacity = '';
      currentPanel.style.filter = '';   
}});    

Spry.Effect.DoFade(nextPanel, {
  duration: 1000, 
  from: 0, 
  to: 100, 
  toggle: false, 
  finish: function() {
      if (self.timerID)
          self.start();
}});
galambalazs
Thanks, galambalazs. That's doing what it should, but the problem is that the second panel is visibly rendering under the first panel (because that's how it's set up in the HTML), as opposed to behind it. Only when it finishes fading does it jump up to where it should be.
Beau
well, now that I know your layout I can tell you that it cannot be done. Because what happened in the original form is that the second one was hidden while the first faded out, then the first became hidden and the second displayed and faded in. That's a trick, they are never ON each other really. So you can't achieve what you want with the current layout.
galambalazs
Yeah, once I saw it with your solution, I figured it probably wasn't possible unless I really redesigned it. Thanks for trying.
Beau
I haven't quite given up on this. If I use galambalazs' solution, but also include`nextPanel.style.position = 'absolute';nextPanel.style.top = '0';`it gets closer, although still not correct.
Beau
A: 

You would need to set their container to be position:relative and then in your code

currentPanel.style.position= 'absolute';
currentPanel.style.zIndex= '10';

nextPanel.style.position = 'absolute';
nextPanel.style.zIndex= '100';
nextPanel.style.opacity = '0';
nextPanel.style.top = '0px';
nextPanel.style.filter = 'alpha(opacity=0)';
self.showPanel(nextPanel);

Spry.Effect.DoFade(currentPanel, {
  duration: 1000, 
  from: 100, 
  to: 0, 
  toggle: false, 
  finish: function() {
      currentPanel.style.opacity = '';
      currentPanel.style.filter = ''; 
      currentPanel.style.zIndex = '0';
}});    

Spry.Effect.DoFade(nextPanel, {
  duration: 1000, 
  from: 0, 
  to: 100, 
  toggle: false, 
  finish: function() {
      if (self.timerID)
          self.start();
}});
Gaby
Thanks, Gaby, but the container doesn't hold its shape when its child goes to absolute positioning. It just shrinks up because it doesn't think it's holding anything.
Beau
Actually, I've got it so that it does bounce back to contain its child, but only after it snaps shut for a second on the fade. Also, the absolutely positioning isn't respecting the top padding (although it probably isn't supposed to), so it's shifted too high. Setting top to 9px or adding a 9px top padding in js causes other problems.
Beau
Also, the positioning isn't an issue on the first transition. Only on subsequent ones does it get messed up. But the container snap, as well as a flash of the current panel at 100% before it fades to the next panel, is consistent throughout.
Beau
you may include the whole page now, or make an example with HTML because we're just guessing without it
galambalazs
@Beau, as @galambalazs says, you will need to provide a full working page (html/css/javascript) somewhere... otherwise we cannot not know specific details that might interfere with the solutions we offer..
Gaby
Guys, I had posted the solution that finally worked for the transition effect. Like I said, the only remaining snag is when the user clicks on an already-faded tab, the content is blank. Thanks.
Beau
A: 

Thanks Galambalazs and Gaby. With your help, I was able to get the solution. After setting the container div's position to relative and defining a height for it, I used the following code to do what I wanted:

    currentPanel.style.zIndex = '0';
    currentPanel.style.opacity = '';
    currentPanel.style.filter = ''; 
    nextPanel.style.position = 'absolute';
    nextPanel.style.top = '9px';
    nextPanel.style.zIndex = '1000';
    nextPanel.style.opacity = '0';
    nextPanel.style.filter = 'alpha(opacity=0)';

Spry.Effect.DoFade(currentPanel, {duration: 500, from: 100, to: 0, toggle: false, finish: function()
{
    self.showPanel(nextPanel);
    currentPanel.style.opacity = '100';
    currentPanel.style.filter = 'alpha(opacity=100)';
}});    

Spry.Effect.DoFade(nextPanel, {duration: 500, from: 0, to: 100, toggle: false, finish: function()
{
    if (self.timerID)
    self.start();
}});
Beau
If anyone's interested, I had to add`currentPanel.style.opacity = '100'; currentPanel.style.filter = 'alpha(opacity=100)';`after `self.showPanel(nextPanel);` in the top portion of the code. Everything works great now.
Beau