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

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: หาขนาด หน้าจอ resulation

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

โดย mindphp » 16/09/2011 3:13 pm

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

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

<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>

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

โดย mindphp » 16/09/2011 3:13 pm

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

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

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' );
    }

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

โดย mindphp » 16/09/2011 3:05 pm

หาขนาด หน้าจอ 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;
    }
    
}

ข้างบน