肯伯恩斯效果与nivo滑块

Ken Burns effect with nivo slider

本文关键字:nivo 滑块 伯恩斯      更新时间:2023-09-26

是否有人设置了nivo滑块来平移每个图像(又名Ken Burns效果)?我正试图实现它,这有点棘手!

实际上,我的实现工作了!

我有一个平移函数循环…像这样:

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

我像这样初始化nivo slider

$('#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');

我还在解决定位的一些问题。

来源&演示

添加到你的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();
}