FeelRightz
FeelRightz

Reputation: 2999

Force Stop Click Event

Fast clicking the .circle , child element star start fadein and fadeout multiple times depend on the clicking. I wish to stop all the star effect when .circle finished the animate. So, I tried to use .off(), but the effect still playing.

What I trying to do is , click .circle effect play, hover end effect directly, click again and playing again. Sorry for my poor english. If I doing it wrong please give some advise , THanks

        $(".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>

Upvotes: 1

Views: 71

Answers (2)

guest271314
guest271314

Reputation: 1

Try substituting .one() for .hover(), utilizing mouseenter event ; use .finish() to stop div elements parent className begins with circleflyingstar animations on hover of .contentitem after first mouseenter event

$(".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);
});
.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>

Upvotes: 3

JanLeeYu
JanLeeYu

Reputation: 1001

Im not so sure if I understand the question but try using .clearQueue() like :

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

Hope this helps.

Upvotes: 0

Related Questions