JQuery

211007_div,z-index

요옫 2021. 10. 7. 10:35

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script src="https://code.jquery.com/jquery-3.5.0.js"></script>

<style type="text/css">

h3 {

width: 400px;

height: 40px;

border: 1px solid #000;

line-height: 40px;

border-radius: 20px;

padding-left: 20px;

text-shadow: 10px 10px 20px yellow;

cursor: pointer;

}

 

h3:active {

border: 5px solid gray;

}

 

div {

position: absolute;

border: 2px solid gray;

width: 300px;

height: 300px;

border-radius: 200px;

}

 

div.pink {

left: 200px;

top: 200px;

background-color: pink;

z-index: 5;  /* 큰 숫자가 위로 올라옴.. 정수, 연속 숫자 아니여도 됨 */

}

 

div.gray {

left: 150px;

top: 300px;

background-color: gray;

z-index: 3;

}

 

div.cyan {

left: 40px;

top: 200px;

background-color: cyan;

z-index: 1;

}

</style>

 

<script type="text/javascript">

$(function () {

 

//z-index: 큰값인 요소가 위로 올라온다, 연속숫자 아니여도 가능

$("h3").click(function() {

 

//클래스 가져오기

var cls=$(this).attr("class");

 

//반복문

if(cls=='pink'){

$("div.pink").css("z-index", "3");  //핑크 숫자가 제일 크면 됨

    $("div.gray").css("z-index", "2");

    $("div.cyan").css("z-index", "1");

} else if (cls=='gray') {

$("div.pink").css("z-index", "2"); 

    $("div.gray").css("z-index", "3");

    $("div.cyan").css("z-index", "1");

} else if (cls=='cyan') {

$("div.pink").css("z-index", "1"); 

$("div.gray").css("z-index", "2");

$("div.cyan").css("z-index", "3");

}

});

});

</script>

 

</head>

<body>

<h3 class="pink">Pink를 제일 위로 올리기</h3>

<h3 class="gray">Gray를 제일 위로 올리기</h3>

<h3 class="cyan">Cyan를 제일 위로 올리기</h3>

 

<div class="pink"></div>

<div class="gray"></div>

<div class="cyan"></div>

</body>

</html>

 

                                           기본화면------------------------- cyan을 제일 위로 올리기 눌렸을 때

'JQuery' 카테고리의 다른 글

211007_animate,z-index  (0) 2021.10.08
211007_animate,active,image  (0) 2021.10.08
211007_trigger  (0) 2021.10.07
211006_이미지의 배경사진 변경  (0) 2021.10.07
211006_on,button(영화관,영화)  (0) 2021.10.06