聚焦时输入元素转换不正确,但选择时则不转换

时间:2015-08-10 20:14:27

标签: javascript html5 css3

我有一个输入元素,我正在它的X轴上进行翻译。当它滑入视图时,我希望它能够被聚焦。

如果我告诉元素要集中注意力 - 过渡会跳跃。如果我告诉元素选择它自己(因此突出显示任何文本本身,但也聚焦) - 转换不会跳转。

为什么?



.filter(...)

var searchInputWrapper = $('.searchInputArea-searchInputWrapper');
var searchButton = $('.searchInputArea-searchButton');
var searchInput = $('.searchInputArea-searchInput');

searchInput.on('blur', function() {
  searchInputWrapper.removeClass('is-active').addClass('is-inactive');
  searchButton.removeClass('is-hidden');
  searchInputWrapper.addClass('is-hidden');
});

searchInput.on('focus', function() {
  console.log('searchInput on focus is ran');
  searchInputWrapper.addClass('is-active').removeClass('is-inactive');
});

$('#click1').click(function() {
  searchButton.addClass('is-hidden');
  searchInputWrapper.removeClass('is-hidden');
  requestAnimationFrame(function() {
    searchInput.focus();
  });
});

$('#click2').click(function() {
  searchButton.addClass('is-hidden');
  searchInputWrapper.removeClass('is-hidden');
  requestAnimationFrame(function() {
    searchInput.select();
  });
});

*,
*:before,
*:after {
  box-sizing: border-box;
}
body {
  width: 640px;
  height: 280px;
}
.flexRow {
  display: flex;
  flex: 1;
  flex-direction: row;
  min-height: 0;
}
.is-hidden {
  display: none !important;
}
.button {
  display: inline-flex;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.button--icon {
  line-height: 0;
}
.button--icon--primary {
  opacity: 0.87;
}
.button--icon--primary:hover:not(.is-disabled) {
  opacity: 1;
}
.button--large {
  width: 48px;
  height: 48px;
}
.searchInputArea {
  border-radius: 2px;
  padding-left: 4px;
  justify-content: flex-end;
  overflow: hidden;
}
.searchInputArea-searchInputWrapper {
  transform: translateX(0);
  transition: transform cubic-bezier(0.39, 0.575, 0.565, 1) 2s, background-color cubic-bezier(0.39, 0.575, 0.565, 1) 2s;
}
.searchInputArea-searchInputWrapper.is-active {
  background-color: rgba(255, 255, 255, 0.15);
}
.searchInputArea-searchInputWrapper.is-active .searchInputArea-searchInput {
  opacity: 1;
}
.searchInputArea-searchInputWrapper.is-inactive {
  transform: translateX(calc(100% - 48px));
}
.searchInputArea-searchIcon,
.searchInputArea-searchButton {
  padding: 0 12px;
}
.searchInputArea-searchInput {
  font: inherit;
  font-size: 17px;
  height: 36px;
  color: inherit;
  background-color: transparent;
  outline: none;
  border: none;
  opacity: 0;
  transition: opacity cubic-bezier(0.39, 0.575, 0.565, 1) 2s;
  flex: 1;
}
.searchInputArea-searchInput::-webkit-input-placeholder {
  color: inherit;
}
.contentBar {
  display: flex;
  padding: 0 4px;
  align-items: center;
  justify-content: flex-end;
  height: 56px;
  color: white;
  fill: white;
  background-color: #4285f4;
}
button {
  width: 100px;
  height: 100px;
}




0 个答案:

没有答案