javascript - 单击不触发 css 动画元素

标签 javascript jquery html css

我有一个小绿色条 contactPull 绝对位于 div box-left 的右侧。我希望在单击 contactPull 时切换 box-left 类。为此,我按原样附上了代码。单击 contactPull 时没有任何反应,也没有打印控制台日志。我尝试对其他几个元素进行同样的处理,效果很好。 我不明白为什么只有 contactPull 不响应我的点击事件。

脚本在最后,这可能是我出错的地方。您可以在脚本后查看 UI。

编辑: 我认为我的动画导致 JQuery 无法切换。似乎只有在 css 动画开始后才会调用 JQuery。如果我错了,请纠正我。有关更新,请参阅 CSS。

CSS:

.arrowRight {
  margin-top: 175px;
  width: 0; 
  height: 0; 
  margin-left: -10px;
  border-top:     15px solid transparent;
  border-bottom:  15px solid transparent;
  border-right:   15px solid #D1F486;
}
.box-left {
  float: left;
  width: 440px;
  height: 352px;
  border-right:   solid 1px #D1F486;
  border-top:     solid 1px #D1F486;
  border-bottom:  solid 1px #D1F486;
  border-left:    solid 4px #D1F486;
  padding: 10px;
  background-color: whitesmoke;
  color: gray;
}
.contactPull {
  position: absolute;
  margin-left: 460px;
  float: right;
  height: 373px;
  width: 5px;
  background-color: #D1F486;
  cursor: pointer;
}
.contactPull:active + .box-left {
  width: 0;
  opacity: 0;
}
.contactPull:active {
  margin-left: 0;
}
.contactPull:active .arrowRight{
  border-left:   15px solid #D1F486;
  border-right: none;
  margin-left: 0;
}

HTML:

<div class="contactPull"><div class="arrowRight"></div></div>
<div class="shown box-left">
    <!-- some unimportant stuff -->
</div>

JS:

$(function () 
{
    $('.contactPull').click(function(e) 
    {
        e.preventDefault();
        $('.box-left').toggleClass("shown hidden");
        console.log("this is the click");
    });
});

enter image description here

最佳答案

你还没有关闭就绪功能...

$(function () {
  $('.contactPull').click(function(e) {
    e.preventDefault();
    $('.box-left').toggleClass("shown hidden");
    console.log("this is the click");
  });
}); <--- missing

关于javascript - 单击不触发 css 动画元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23172593/

相关文章:

javascript - jQuery AJAX POST - 数据未发送

javascript - 使用多个括号在 Javascript 中关闭

jquery - Google Maps API 3 存在问题

javascript - jQuery UI 自动完成 - 外部 javascript 数据源的语法?

javascript - 在 onDeviceReady 中调用时函数无法正常工作

javascript - 到达页面末尾时翻转弹出窗口的方向

html - 溢出 :hidden in Chrome doesn't work

javascript - 带有圆 Angular 的html5 Canvas 三 Angular 形

javascript - 在 url 参数中进行 Angular 插值 {{ }},有没有办法清理 url?

javascript - 开发 3D 交互式图像功能的方向