หาขนาด หน้าจอ resulation

รวมโค้ด AJAX Javascript Library jQuery Framework ต่างๆ ที่ใช้ คู่กับ php Script Ajax โค้ด Ajax Prototype UI แนะนำได้ที่นี่

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

หาขนาด หน้าจอ resulation

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

หาขนาด หน้าจอ resulation

โค้ด: เลือกทั้งหมด

function get_resulation()
{
    var width, height;
    if(window.innerWidth) {
        width = window.innerWidth;
        height = window.innerHeight;
    }
    else if(document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    }
    else if(document.body.clientWidth) {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    
}
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: หาขนาด หน้าจอ resulation

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

กำหนดพื้นหลังตามขนาดหน้าจอ

โค้ด: เลือกทั้งหมด

if (document.viewport.getDimensions()­ .getHeight() == 800) {
    $( 'body' ).setAttribute( 'background', '/img/bg-800x600.gif' );
} else if (document.viewport.getDimensions()­ .getHeight() == 1280) {
    if (document.viewport.getDimensions()­ .getWidth() == 768) {
        $( 'body' ).setAttribute( 'background', '/img/bg-1280x768.gif' );
    } else if (document.viewport.getDimensions()­ .getWidth() == 1024) {
        $( 'body' ).setAttribute( 'background', '/img/bg-1280x1024.gif' );
    } else {
        $( 'body' ).setAttribute( 'background', '/img/bg-1280x1200.gif' );
    }
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: หาขนาด หน้าจอ resulation

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

โชว์ขนาดหน้าจอที่ให้อยู่

โค้ด: เลือกทั้งหมด

<html>
<head>
<link id="stylesheetLink" rel="stylesheet" href="#" />
<script language="JavaScript">
var smallStylesheetLink = "small.css";
var normalStylesheetLink = "normal.css";

function setStyle() {
    var width, height;
    if(window.innerWidth) {
        width = window.innerWidth;
        height = window.innerHeight;
    }
    else if(document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
        height = document.documentElement.clientHeight;
    }
    else if(document.body.clientWidth) {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    var stylesheetLink = document.getElementById("stylesheetLink");
    var useSmall = (width <= 800 && height <= 600);
//    stylesheetLink.setAttribute("href", (useSmall ? smallStylesheetLink : normalStylesheetLink));
	alert(width);
	alert(height);
	
}

setStyle();
</script>
</head>
<body>
<h1>Using Different Stylesheets</h1>
</body>
</html>
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 65