简体   繁体   English

从左向右滚动Flex Flex div动画

[英]Animate Scroll Flex div to right from left

On click of a panel (say panel1 ) I am trying to animate scroll to the newly added panel ( panel2 ) to left side of the screen. 在单击面板(例如panel1 )时,我试图使滚动到屏幕左侧的新添加的面板( panel2 )动画。
I have tried 我努力了

windows.location = '#p2' // panel2 id 

but that doesn't animate and bluntly takes the focus to the new panel 但这并没有生气蓬勃,并且直截了当地将焦点转移到了新面板上

Here is the JSFiddle . 这是JSFiddle

Note : I am not sure jquery or CSS animations can be done here. 注意 :我不确定可以在这里完成jquery或CSS动画。 looking for CSS animations 寻找CSS动画

You can use jQuery to animate your container so the new panel ( panel2 ) is visible in the view port. 您可以使用jQuery为容器设置动画,以便新面板( panel2 )在查看端口中可见。

https://jsfiddle.net/wtfc8o2t/6/ https://jsfiddle.net/wtfc8o2t/6/

function addPanel(elemId) {
  document.getElementById(elemId).style.display = 'flex';
  $( "#flex-container" ).animate({
    left: "-=450"
  }, 1000, function() {
    // Animation complete.
  });
}

You can do like this: 您可以这样:

function addPanel(elemId) {
  $('#'+elemId).css('display', 'flex');
  $('html, body').animate({
    scrollLeft: $('#'+elemId).offset().left
  }, 1000, function() {
    // Animation complete.
  });
}

Working fiddle 工作提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM