Ken Burns 效果与 nivo 滑块

发布于 2024-12-09 03:47:45 字数 191 浏览 0 评论 0原文

有没有人设置 nivo 滑块 来平移每个图像(又名 肯·伯恩斯效应)?我正在尝试实现它,但有点棘手!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

带刺的爱情 2024-12-16 03:47:45

事实上,我的实施工作已经开始工作了!

我有一个平移功能循环..像这样:

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

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

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.

情愿 2024-12-16 03:47:45

来源 & 演示

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

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文