强制停止单击事件

时间:2016-03-17 02:56:45

标签: javascript jquery

快速点击.circle,子元素star开始fadeinfadeout多次取决于点击次数。我希望在stop完成动画时star所有.circle效果。所以,我尝试使用.off(),但效果仍在播放。

我要做的是,点击.circle效果播放,直接悬停效果,再次点击再播放。抱歉我的英语不好。如果我做错了,请给一些建议,谢谢

        $(".contentitem").hover(
            function (e) {
                var dataid = $(this).data("id");
                var videoposition_top = $("#contentitem_" + dataid).position().top + 100;
                $(".circle").stop().animate({ 'top': videoposition_top + "px" }, 500, function () {
                    $(".circle").off();
                });

            }, // over
            function (e) {
                var dataid = $(this).data("id");
                var videoposition_top = $("#contentitem_" + dataid).position().top + 100;
                $(".circle").stop().animate({ 'top': videoposition_top + "px" }, 500, function () {
                    $(".circle").off();
                });

            }  // out
        );
        $(".circle").on('click',function(){
            $(".circleflyingstar div.star06").fadeIn(100).delay(500).fadeOut(100);
            $(".circleflyingstar div.star02").fadeIn(200).delay(500).fadeOut(200);
            $(".circleflyingstar div.star05").fadeIn(300).delay(500).fadeOut(300);
            $(".circleflyingstar div.star03").fadeIn(400).delay(500).fadeOut(400);
            $(".circleflyingstar div.star04").fadeIn(500).delay(500).fadeOut(500);
            $(".circleflyingstar div.star01").fadeIn(600).delay(500).fadeOut(600);
        });
.circle
{
    height: 50px;
    width: 50px;
    position: absolute;
    border-radius: 50%;
    background-color: #fff;
    z-index: 5;
    border: 1px solid #ccc;
    left: 0px;
    top: 50px;
    cursor: pointer;
    border-top: 5px solid #EC9397;
    border-left: 5px solid #EC9397;
    border-bottom: 5px solid #F2C90D;
    border-right: 5px solid #F2C90D;
  left:50px;
  top:100px;
}
.circleflyingstar
{
    position: absolute;
    top: -110px;
}
.circleflyingstar div.star01{
  width:20px;
  height:20px;
  background-color:rgba(0,0,0,0.2);
    position:absolute;
  left:-20px;
  }
.circleflyingstar div.star02{
   width:20px;
  height:20px;
  background-color:rgba(0,0,0,0.4); 
  position:absolute;
    top: 35px;
    left: 20px;
    display:none;
  }
.circleflyingstar div.star03{
    width:20px;
  height:20px;
  background-color:rgba(0,0,0,0.6);
      top: 20px;
    display:none;
  }
.circleflyingstar div.star04{
    width:20px;
  height:20px;
  background-color:rgba(0,0,0,0.8);
        position: absolute;
     display:none;
  }
.circleflyingstar div.star05{
    width:20px;
  height:20px;
  background-color:rgba(0,0,0,1);
      position: absolute;
    top: 34px;
    left: -6px;
    display:none;
  }
.circleflyingstar div.star06{
    width:20px;
  height:20px;
  background-color:rgba(0,0,0,0.2);
      position: absolute;
    top: 65px;
    left: -10px;
    display:none;
  }

.contentitem{
  width:500px;
  height:400px;
  background-color:#123;
  margin-left:100px;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="circle">
        <div class="circleflyingstar">
            <div class="star01"></div>
            <div class="star02"></div>
            <div class="star03"></div>
            <div class="star04"></div>
            <div class="star05"></div>
            <div class="star06"></div>
        </div>
    </div>


<div id="contentitem_123456" class="contentitem" data-id="123456"></div>

2 个答案:

答案 0 :(得分:3)

尝试使用.hover()替换.one()替换mouseenter;在.finish()事件发生后,使用div来阻止className元素circleflyingstar元素从hover .contentitem mouseenter开始p>

&#13;
&#13;
$(".contentitem").one("mouseenter", 
  function(e) {
    var dataid = $(this).data("id");
    var videoposition_top = $("#contentitem_" + dataid).position().top + 100;
    $(".circle").stop().animate({
      'top': videoposition_top + "px"
    }, 500);
    $(this).mouseenter(function() {
      $("[class^=circleflyingstar] div").finish()
    })
  }
);
$(".circle").on('click', function() {
  $(".circleflyingstar div.star06").fadeIn(100).delay(500).fadeOut(100);
  $(".circleflyingstar div.star02").fadeIn(200).delay(500).fadeOut(200);
  $(".circleflyingstar div.star05").fadeIn(300).delay(500).fadeOut(300);
  $(".circleflyingstar div.star03").fadeIn(400).delay(500).fadeOut(400);
  $(".circleflyingstar div.star04").fadeIn(500).delay(500).fadeOut(500);
  $(".circleflyingstar div.star01").fadeIn(600).delay(500).fadeOut(600);
});
&#13;
.circle {
  height: 50px;
  width: 50px;
  position: absolute;
  border-radius: 50%;
  background-color: #fff;
  z-index: 5;
  border: 1px solid #ccc;
  left: 0px;
  top: 50px;
  cursor: pointer;
  border-top: 5px solid #EC9397;
  border-left: 5px solid #EC9397;
  border-bottom: 5px solid #F2C90D;
  border-right: 5px solid #F2C90D;
  left: 50px;
  top: 100px;
}
.circleflyingstar {
  position: absolute;
  top: -110px;
}
.circleflyingstar div.star01 {
  width: 20px;
  height: 20px;
  background-color: rgba(0, 0, 0, 0.2);
  position: absolute;
  left: -20px;
}
.circleflyingstar div.star02 {
  width: 20px;
  height: 20px;
  background-color: rgba(0, 0, 0, 0.4);
  position: absolute;
  top: 35px;
  left: 20px;
  display: none;
}
.circleflyingstar div.star03 {
  width: 20px;
  height: 20px;
  background-color: rgba(0, 0, 0, 0.6);
  top: 20px;
  display: none;
}
.circleflyingstar div.star04 {
  width: 20px;
  height: 20px;
  background-color: rgba(0, 0, 0, 0.8);
  position: absolute;
  display: none;
}
.circleflyingstar div.star05 {
  width: 20px;
  height: 20px;
  background-color: rgba(0, 0, 0, 1);
  position: absolute;
  top: 34px;
  left: -6px;
  display: none;
}
.circleflyingstar div.star06 {
  width: 20px;
  height: 20px;
  background-color: rgba(0, 0, 0, 0.2);
  position: absolute;
  top: 65px;
  left: -10px;
  display: none;
}
.contentitem {
  width: 500px;
  height: 400px;
  background-color: #123;
  margin-left: 100px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="circle">
  <div class="circleflyingstar">
    <div class="star01"></div>
    <div class="star02"></div>
    <div class="star03"></div>
    <div class="star04"></div>
    <div class="star05"></div>
    <div class="star06"></div>
  </div>
</div>


<div id="contentitem_123456" class="contentitem" data-id="123456"></div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

我不确定我是否理解了这个问题,但尝试使用.clearQueue()之类的:

$(".circleflyingstar div.star06").clearQueue();

希望这有帮助。