HTML Window moveBy() วิธีการย้ายหน้าต่างที่สัมพันธ์กับพิกัดปัจจุบัน
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
window.moveBy(x,y)
ในที่นี้ x และ y กำหนดค่าของการย้ายหน้าต่างในแนวนอนและแนวตั้งเป็นพิกเซลตามลำดับ
ให้เราดูตัวอย่างของ HTML Window moveBy() Method -
ตัวอย่าง
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background-color: #8BC6EC;
background-image: linear-gradient(135deg, #8BC6EC 0%, #9599E2 100%) no-repeat;
text-align: center;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
<body>
<h1>HTML Window moveBy() Method Demo</h1>
<button onclick="create()" class="btn">Create new window and then move it</button>
<script>
function create(){
var newWindow =window.open('','','width=150,height=150');
newWindow.moveBy(550, 200);
}
</script>
</body>
</html> ผลลัพธ์

คลิกที่ “สร้างหน้าต่างใหม่แล้วย้าย ” เพื่อสร้างหน้าต่างใหม่แล้วย้ายโดยใช้วิธี moveBy():
