【问题标题】:resetting a div after animation动画后重置 div
【发布时间】:2017-08-28 02:13:57
【问题描述】:

我在创建动画后尝试将包含图像的 div 重置为原始值时遇到问题。

所以我有一个测验,有 6 张图片并排放置。 用户必须选择 6 张图片中的一张。当点击那张图片时,我让图片全屏显示。之后,当用户双击图片时,图片应该回到原来的位置进行下一个问题。

但是返回不起作用,我不明白为什么。

注意:divsare 浮动 div 具有特定的左侧位置,所以我需要保留这些...

这是动画代码:

$(".candidatePicture").click(function(e){
      $(e.target).css('z-index', 1); 
      $(e.target).animate({top: '0', left: '0', width: '1920px', height: '1080px'}, 1000);
    });

这是返回码:

$(".candidatePicture").css({ 'width': '250px', 'height': '300px', 'z-index': '0' });   

您可以在这里找到代码:http://jsbin.com/gotuqenoce

感谢您的帮助。

【问题讨论】:

标签: javascript jquery css jquery-animate


【解决方案1】:

请尝试更改事件处理程序如下:

$(".candidatePicture").click(function(e){
  var $this = $(this);
  $this.css('z-index', 1); 
  $this.animate({top: '0', left: '0', width: '1920px', height: '1080px'}, 1000);
  $this.off("click");
});
$( ".candidatePicture" ).dblclick(function(e) {
  $(this).css({ top: '', left: '', 'width': '', 'height': '', 'z-index': '' });
  showNextQuestion();
});

http://jsbin.com/latiqemozo/edit?html,output

【讨论】:

  • 感谢 itacode,但当我尝试此操作时,它会很好地重置我的 z-index,但图片保持全屏并且未调整为 250px X 300px
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多