【问题标题】:Ken Burns effect with nivo slider带有 nivo 滑块的 Ken Burns 效果
【发布时间】:2011-10-10 22:47:53
【问题描述】:

有没有人设置nivo slider 来平移每个图像(又名Ken Burns effect)?我正在尝试实现它,这有点棘手!

【问题讨论】:

  • 如果这就是你所需要的,为什么还需要 nivo 呢?
  • 因为我还需要在幻灯片之间进行渐变。我尝试自己实现,但很困难,我决定使用 nivo 滑块。

标签: javascript jquery nivo-slider


【解决方案1】:

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

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

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 滑块:

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

我仍在解决一些定位问题。

【讨论】:

  • 有人用这个解决过职位问题吗?
【解决方案2】:

Source & Demo

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-15
    相关资源
    最近更新 更多