5

Has anyone set up a nivo slider to pan each image (aka Ken Burns effect)? I'm trying to implement it and it's kinda tricky!

John Carter
  • 50,377
  • 25
  • 100
  • 137
nnyby
  • 4,125
  • 8
  • 45
  • 95
  • Why do you need nivo to do that if that's all you need? – Rob Oct 10 '11 at 22:49
  • Because I also need fading between the slides. I tried to implement that myself, but it was difficult and I decided to go with nivo slider. – nnyby Oct 10 '11 at 22:50

2 Answers2

4

Actually, I got my implementation working!

I have a panning function loop.. something like this:

function ken_burns_loop(el) {
  $(el)
    .animate({
      'background-position-x': '40%',
      'background-position-y': '60%'
    }, 8000, 'linear')
    .animate({
      'background-position-x': '30%',
      'background-position-y': '40%'
    }, 8000, 'linear')
    .animate({
      'background-position-x': '70%',
      'background-position-y': '70%'
    }, 8000, 'linear', function() { ken_burns_loop(el); });
}

And I'm initializing nivo slider like this:

$('#welcome-slider').nivoSlider({
  effect: 'fade',
  slices: 1,
  directionNav: false,
  afterChange: function() {
    $('#welcome-slider, .nivo-slice').stop(true);
    ken_burns_loop('#welcome-slider, .nivo-slice');
  }
});
ken_burns_loop('#welcome-slider, .nivo-slice');

I'm still working out some problems with positioning.

nnyby
  • 4,125
  • 8
  • 45
  • 95
0

Source & Demo

Add this to your JS:

if(currentEffect === 'kenburns'){
  createZoom(slider, settings, vars);
  zoom = $('.nivo-zoom:last', slider);
  var delta = (8 + Math.random() * 2) / 100;
  var neww = zoom.width() * (1 + delta);
  var newh = zoom.height() * (1 + delta);
  var x = delta * zoom.width(); //Math.random()*(neww-zoom.width());
  var y = delta * zoom.height(); //Math.random()*(newh-zoom.height());
  var zoomdir = Math.round(Math.random() * 4);
  zoom.animate({ opacity:'1.0'}, {easing:'linear',duration:settings.pauseTime*2/3});
  if(zoomdir == 1) {
    zoom.find('img').animate({ height:newh+'px',width:neww+'px',left: '-'+x+'px',top: '-'+y+'px'},{easing:'linear',duration:settings.pauseTime*4/3, complete: function(){ slider.trigger('nivo:animFinished'); }});
  } else if(zoomdir == 2) {
    zoom.find('img').animate({ height:newh+'px',width:neww+'px',right: '-'+x+'px',top: '-'+y+'px'}, {easing:'linear',duration:settings.pauseTime*4/3, complete: function(){ slider.trigger('nivo:animFinished'); }});
  } else if(zoomdir == 3) {
    zoom.find('img').animate({ height:newh+'px',width:neww+'px',right: '-'+x+'px',bottom: '-'+y+'px'}, {easing:'linear',duration:settings.pauseTime*4/3, complete: function(){ slider.trigger('nivo:animFinished'); }});
  } else {
    zoom.find('img').animate({ height:newh+'px',width:neww+'px',left: '-'+x+'px',bottom: '-'+y+'px'}, {easing:'linear',duration:settings.pauseTime*4/3, complete: function(){ slider.trigger('nivo:animFinished'); }});
  }
  if($('.nivo-zoom', slider).length > 2) $('.nivo-zoom:first', slider).remove();
}
cfx
  • 2,885
  • 2
  • 30
  • 43