3

I'm scrolling some panels which contain some YouTube clips using jQuery Tools Scrollable. I'd like to hide them during the transition to avoid a jerky animation.

Markup:

<div id="panel_items">
    <div id="wrap">
        <div class="event">
            <div class="header">Event 1</div><!-- Header is always displayed -->
            <div class="youtube">youtube clips</div><!-- hide during transition, then show -->
        </div>
        <div class="event">
            <div class="header">Event 2</div>
            <div class="youtube" style="display: none">More youtube clips</div>
        </div>
    </div>
</div>

Current JS:

$("#panel_items").scrollable({
  onBeforeSeek: function() { console.log("hide .child .youtube"); }, 
  onSeek: function() { console.log("Show child .youtube"); }        
});

Bonus question: How can I automatically set the height of #panel_items to match the current panel height (.event)?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Rick
  • 273
  • 1
  • 9
  • 23

3 Answers3

1

Something like this might work (untested):

$("#panel_items").scrollable({
   onBeforeSeek: function() { this.getItems().css({'visibility': 'hidden'}); }, 
   onSeek: function() { this.getItems().css({'visibility': 'visible'});}
});  
Shaun Scovil
  • 3,905
  • 5
  • 39
  • 58
1

Did you try it like that? :

var api = jQuery("#panel_items").data("scrollable");

api.onBeforeSeek(function() {

    jQuery(". youtube").fadeOut(100);

});
madmax
  • 1,803
  • 3
  • 25
  • 50
0

fadein and fadeout throws off the count. After some testing, this works:

onBeforeSeek: function (e,i) {
    $(".items").animate({opacity:0},400);
},
onSeek: function (e,i) {
    $(".items").animate({opacity:1},400);
}
the Tin Man
  • 158,662
  • 42
  • 215
  • 303