dimanche 30 novembre 2014

hide first div before displaying next


I have four hidden divs that are shown via jquery when icons on a map are clicked. The display div shows details about each location. I want to have that display clear out each time a different location is clicked, so that only one set of details is shown at a time. Right now, whenever I click an icon, it adds to the list instead of clearing out what is currently there.


HTML:



<div id="1" class="toggle" style="display:none">test text 1</div>
<div id="2" class="toggle" style="display:none">test text 2</div>
<div id="3" class="toggle" style="display:none">test text 3</div>
<div id="4" class="toggle" style="display:none">test text 4</div>


JS:



var drawCircle = function (context, x, y, fillcolor, radius, linewidth, strokestyle, fontcolor, textalign, fonttype, filltext, div, circles) {
draw(context, x, y, fillcolor, radius, linewidth, strokestyle, fontcolor, textalign, fonttype, filltext);
var circle = new Circle(x, y, radius);
circles.push(circle);
};

drawCircle(context, 300, canvas.height / 2, "green", 40, 5, "#003300", "white", "center", "bold 32px Arial", "1", "#2", circles);
drawCircle(context, 600, canvas.height / 3, "blue", 50, 5, "#003300", "white", "center", "bold 32px Arial", "2", "#3", circles);

$('#mapCanvas').click(function (e) {
var clickedX = e.pageX - this.offsetLeft;
var clickedY = e.pageY - this.offsetTop;

for (var i = 0; i < circles.length; i++) {
if (clickedX < circles[i].right && clickedX > circles[i].left && clickedY > circles[i].top && clickedY < circles[i].bottom) {

$('#'+(i+1)).show();


}
}




Aucun commentaire:

Enregistrer un commentaire