CSS延迟:活动选择器生效

时间:2011-06-07 04:50:13

标签: html css

我无法让CSS 3按钮正常运行。您可以在one of my project pages查看按钮。问题是在:active CSS选择器生效之前有一秒左右的延迟,使按钮略微移动并改变阴影;它之前没有这样做过。这是Sass代码:

@mixin transition($type, $time, $ease) {
  -webkit-transition: $type $time $ease;
  transition: $type $time $ease;
}

@mixin border-radius($length) {
  border-radius: $length;
  -webkit-border-radius: $length;
  -moz-border-radius: $length;
}

.project-download {
  color: #000300;
  background-color: #00910A;
  padding: 10px;
  position: relative;
  text-align: center;
  font-size: 24px;
  font-weight: bold;

  @include transition(background-color, 0.2s, linear);
  @include border-radius(10px);

  box-shadow:
    1px 1px 0 0 #014D06,
    2px 2px 0 0 #014D06,
    3px 3px 0 0 #014D06,
    4px 4px 0 0 #014D06,
    5px 5px 5px 0 #000000;

  -webkit-box-shadow:
    1px 1px 0 0 #014D06,
    2px 2px 0 0 #014D06,
    3px 3px 0 0 #014D06,
    4px 4px 0 0 #014D06,
    5px 5px 5px 0 #000000;

  -moz-box-shadow:
    1px 1px 0 0 #014D06,
    2px 2px 0 0 #014D06,
    3px 3px 0 0 #014D06,
    4px 4px 0 0 #014D06,
    5px 5px 5px 0 #000000;

  &:hover { background-color: #00B00C; }
  &:active {
    box-shadow: 1px 1px 5px 0 #000000;
    -webkit-box-shadow: 1px 1px 5px 0 #000000;    
    -moz-box-shadow: 1px 1px 5px 0 #000000;
    top: 4px;
    left: 4px;
  }
}

将CSS翻译为:

.project-download {
  color: #000300;
  background-color: #00910A;
  padding: 10px;
  position: relative;
  text-align: center;
  font-size: 24px;
  font-weight: bold;

  box-shadow:
    1px 1px 0 0 #014D06,
    2px 2px 0 0 #014D06,
    3px 3px 0 0 #014D06,
    4px 4px 0 0 #014D06,
    5px 5px 5px 0 #000000;

  -webkit-box-shadow:
    1px 1px 0 0 #014D06,
    2px 2px 0 0 #014D06,
    3px 3px 0 0 #014D06,
    4px 4px 0 0 #014D06,
    5px 5px 5px 0 #000000;

  -moz-box-shadow:
    1px 1px 0 0 #014D06,
    2px 2px 0 0 #014D06,
    3px 3px 0 0 #014D06,
    4px 4px 0 0 #014D06,
    5px 5px 5px 0 #000000;

  border-radius: 10px;
  -webkit-border-radius: 10px;
  -moz-border-radius: 10px;

  -webkit-transition: background-color 0.2s linear;
  transition: background-color 0.2s linear;
}

.project-download:active {
  box-shadow: 1px 1px 5px 0 #000000;
  -webkit-box-shadow: 1px 1px 5px 0 #000000;    
  -moz-box-shadow: 1px 1px 5px 0 #000000;
  top: 4px;
  left: 4px;
}

.project-download:hover { background-color: #00B00C; }

我搜索了一下没有运气的谷歌。有什么想法吗?

修改: 我通过使用这个JavaScript函数解决了Clicky造成的问题:

function removeLinkListeners()
{
  var links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; i++)
  {
    if (links[i].classList.contains('project-download-link'))
    {
      links[i].removeEventListener('mousedown', clicky.outbound);
    }
  }
}

将初始化脚本更改为:

<script type="text/javascript">
try
{
  clicky.init(234973);
  window.onload = removeLinkListeners;
}
catch(e) {}
</script>

1 个答案:

答案 0 :(得分:4)

如果您将代码放在jsfiddle示例中......

http://jsfiddle.net/zfFtv/

你会注意到没有延迟。所以我怀疑这是你的javascript。也许getclicky代码效率不高,当你点击它时会导致延迟?尝试逐个禁用js文件以查明问题。