jquery click the button pop-up picture

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="js/jquery-3.4.1.min.js"></script>
<title>Document</title>

<style>
.bor{
border: 2px solid red;
width: 400px;
height: 200px;
text-align: center;
}
#main {
margin-top: 50px;
border: 1px solid black;
cursor: pointer;
padding: 30px;
}

#qrcode img {
position: absolute;
top: 50%;
left: 40%;
width: 300px;
height: 300px;
display: block;
}
#qrcode {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.6);
z-index: 9999;
display: none;
}
</style>
</head>
<body>
<div class="bor">
<button class="main">点击此处 弹出你想要的</button>
<div class="qrcode">
<img class="image"  width="100%" height="100%" src="img/12.png">
</div>
</div>
<div class="bor">
<button class = "main"> Click here to pop-up you want </ the Button>
<div class = "qrcode">
<img class = "Image" width = "100%" height = "100%" src = " img / 12.png ">
</ div>
</ div>

<Script>
// when this page there are two buttons click event when, not suitable for id (because id is unique), it is necessary to change the id for the class the most simple way to modify;
// this will achieve the effect you want, click the button pop-up picture

$(function() {
$(".main").click(function() {
$(".qrcode").fadeIn("slow");
});
$(".qrcode").click(function() {
$(".qrcode").fadeOut("slow");
})
});

 // This code suitable for the present page is only a button click
$ (function () {
$ ( "# main") the Click (function () {.
$ ( "# Qrcode") fadeIn ( "SLOW");.
});
$ ( "# qrcode") the Click (function () {.
$ ( "# qrcode"). fadeOut ( "SLOW");.
})
});

</script>
</body>
</html>

These are the use jquery inside fade () function to write the Click event.

 

The following is written in the traditional onclick, a little small problem, just beginning to be effective, do not know after today, why did not re-write the results, you can help me see, I also publish it

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="js/jquery-3.4.1.min.js"></script>
<title>Document</title>

<style>
.bor{
border: 2px solid red;
width: 400px;
height: 200px;
text-align: center;
}
#main {
margin-top: 50px;
border: 1px solid black;
cursor: pointer;
padding: 30px;
}

#qrcode img {
position: absolute;
top: 50%;
left: 40%;
width: 300px;
height: 300px;
display: block;
}
#qrcode {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.6);
z-index: 9999;
display: none;
}
</style>
</head>
<body>
<div class="bor">
<button id="main">点击此处 弹出你想要的</button>
<div id="qrcode">
<img id="image" onclick="test(this)" width="100%" height="100%" src="img/12.png">
</div>
</div>
<div class="bor">
<button id="main">点击此处 弹出你想要的</button>
<div id="qrcode">
<img id="image" onclick="test(this)" width="100%" height="100%" src="img/12.png">
</div>
</div>

<script>

// The traditional way to write, onclick

function test(obj){
console.log("11111")
$(obj).next().fadeIn("slow");
$(obj).next().click(function() {
$(this).fadeOut("slow");
})
var hh = $(obj).next().html();
console.log(hh)
}

</script>
</body>
</html>

Guess you like

Origin www.cnblogs.com/qiaomeier/p/11589951.html