1

I want to "shake" an <img> element by constantly moving it between

transform: translateX(-50px);

and

transform: translateX(50px);

Using D3.js, like here: http://plnkr.co/edit/uJeqkizCXcPDmaJazOPa?p=preview , the circle will not even be interpolated. How can I move it smoothly?

2

1 Answer 1

1

Hope this helps. Don't forget to clear the interval.

var svg = d3.select("#cont").append("svg")
	.attr("width", 400)
	.attr("height", 400);
	
	
	
	var circle = svg.append("circle")
	.attr("cx", 200)
	.attr("cy", 200)
	.attr('r', 10)
    .style('fill', 'black');
	
function trans(){
  circle
  .transition()
  .attr("cx",250)
  .each("end",function() {
    d3.select(this).       
      transition()         
        .attr("cx",200);   
                           
   });
}
 setInterval(function(){trans()}, 500);
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<div id="cont"></div>

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I didn't specify this correctly. My actual element is no circle, but an <img> tag, so manipulating cx and cy won't work. I really want to know about a translate interpolation that is as easy as possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.