--แต่สิ่งที่จะกล่าวถึงนี้ คือการทำงานของ หน้าต่าง pop-up ภายในหน้าเดียวกัน แล้วก็ต้องมาเสียเวลาปิด มัน
--เรามาเริ่มทดลองทำกันเลย
ขั้นตอนการทำงาน
1.เราจะต้องเขียนโคด html ขั้นว่าเพื่อเป็นปุ่ม สำหรับกกดเเล้วเป้น pop-up
**ตัวอย่างโคด**
โค้ด: เลือกทั้งหมด
<button type="button" class="button button-icon-only bbcode-img" accesskey="p" name="addbbcode14" value="Img" onclick="mpopimg()" title="{L_BBCODE_P_HELP}">
<i class="icon fa fa-file-image-o" aria-hidden="true"></i>
</button>
**ตัวอย่างโคด**
โค้ด: เลือกทั้งหมด
<div id="light" class="white_content">
<div class="messagebox_spacer">
<a href="javascript:void(0)" onclick="document.getElementById('light').style.display = 'none';document.getElementById('fade').style.display = 'none'" >X</a>
<div id="uploader" >
<p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
</div>
<br />
</div>
</div>
<div id="fade" class="black_overlay"></div>
3. CSS สำหรับการทำ หน้าต่าง pop-up
**ตัวอย่างโคด**
โค้ด: เลือกทั้งหมด
<style type="text/css">
black_overlay {
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index: 1001;
-moz-opacity: 0.8;
opacity: .80;
filter: alpha(opacity=80);
}
.white_content {
display: none;
position: absolute;
top: 25%;
left: 25%;
width: 50%;
height: 50%;
padding: 2px;
border: 0px solid #000;
background-color: white;
z-index: 1002;
overflow: visible;
}
es fadeup {
to {
transform: translateY(0);
opacity: 1;
}
}
@keyframes faderight {
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes fade {
to {
opacity: 1;
}
}
@media (max-width: 400px){
width: 100%;
height: 100%;
}
</style>
**ตัวอย่างโคด**
4.1 javascript สำหรับเรียก pop-up
โค้ด: เลือกทั้งหมด
function mpopimg()
{
document.getElementById('light').style.display = 'block';
document.getElementById('fade').style.display = 'block';
}
4.2 javascript สำหรับปิด pop-up *นำไปไว้หลังโคดการทำงาน บรรทัดสุดท้าย
โค้ด: เลือกทั้งหมด
{
document.getElementById('light').style.display = 'none';
document.getElementById('fade').style.display = 'none';
}