javascript - Drag and drop takes me to a different website if false or restarts animation if true -
i've got animation: http://codepen.io/tiamat/pen/jrdvx when colored circle goes black 1 restarts animation. when not go it takes me circle.com website. can stop both of these actions? if successful, not restart animation, colored circle remain in black one.
html:
<div id="intreg" style="border:1px solid #000000; width:750px; height: 550px;" > <div id="jos"> <div id="square_drop"ondragenter="return dragenter(event)" ondrop="return dragdrop(event)" ondragover="return dragover(event)"></div> <div id="circle_drop"ondragenter="return dragenter(event)" ondrop="return dragdrop(event)" ondragover="return dragover(event)"></div> </div> <div id="sus"> <div id="triangle_drop"ondragenter="return dragenter(event)" ondrop="return dragdrop(event)" ondragover="return dragover(event)"></div> <div id="square" draggable="true"ondragstart="return dragstart(event)"></div> <div id="circle" draggable="true"ondragstart="return dragstart(event)"></div> <div id="triangle" draggable="true"ondragstart="return dragstart(event)"></div> </div> </div>
javascript:
function dragstart(ev) { ev.datatransfer.effectallowed='move'; ev.datatransfer.setdata("text", ev.target.getattribute('id')); ev.datatransfer.setdragimage(ev.target,100,100); return true; } function dragenter(ev) { event.preventdefault(); return true; } function dragover(ev) { event.preventdefault(); } function dragdrop(ev) { var data = ev.datatransfer.getdata("text"); ev.target.appendchild(document.getelementbyid(data)); ev.stoppropagation(); return false; }
css:
#square { -webkit-animation: move4 3s forwards linear ; -moz-animation: move4 3s forwards linear ; -o-animation: move4 3s forwards linear ; } @-webkit-keyframes move4 { 0% {margin-bottom: -400px;margin-left:-100px;} 100% {margin-top: -130px;margin-left: 400px;} } @-moz-keyframes move4 { 0% {margin-top: 1400px;margin-left:-100px;} 100% {margin-top: 30px;margin-left: 400px;} } @-o-keyframes move4 { 0% {margin-bottom: -400px;margin-left:-100px;} 100% {margin-top: -130px;margin-left: 400px;} } #circle { -webkit-animation: move5 3s forwards linear ; -moz-animation: move5 3s forwards linear ; -o-animation: move5 3s forwards linear ;} @-webkit-keyframes move5 { 0% {margin-top: 1000px;margin-left:-100px;} 100% {margin-top: -40px;margin-left: 150px;} } @-moz-keyframes move5 { 0% {margin-top: 1000px;margin-left:-100px;} 100% {margin-top: -40px;margin-left: 150px;} } @-o-keyframes move5 { 0% {margin-top: 1000px;margin-left:-100px;} 100% {margin-top: -40px;margin-left: 150px;} } #triangle { -webkit-animation: move6 3s forwards linear ; -moz-animation: move6 3s forwards linear ; -o-animation: move6 3s forwards linear ; } @-webkit-keyframes move6 { 0% {margin-top: 1000px;margin-left:-100px;} 100% {margin-top: -120px;margin-left: 20px;} } @-moz-keyframes move6 { 0% {margin-top: 1000px;margin-left:-100px;} 100% {margin-top: -120px;margin-left: 20px;} } @-o-keyframes move6 { 0% {margin-top: 1000px;margin-left:-100px;} 100% {margin-top: -120px;margin-left: 20px;} }
for case colored circle dropped on black one: when append dropped element, re-rendered in new location, including animation specified in style. try creating class removes animations
#circle.stay { -webkit-animation: none !important; -moz-animation: none !important; -o-animation: none !important; }
and add class element before appending new home:
function dragdrop(ev) { var data = ev.datatransfer.getdata("text"); var el = document.getelementbyid(data); el.classname="stay"; ev.target.appendchild(el); ev.stoppropagation(); return false; }
for case misses, add ondrop handler body
element cancels drag
<body ondrop="return false">
Comments
Post a Comment