2013-12-14 2 views
0
<!-- 

var viewportwidth; 
var viewportheight; 

// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight 

if (typeof window.innerWidth != 'undefined') 
{ 
     viewportwidth = window.innerWidth, 
     viewportheight = window.innerHeight 
} 

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) 

else if (typeof document.documentElement != 'undefined' 
    && typeof document.documentElement.clientWidth != 
    'undefined' && document.documentElement.clientWidth != 0) 
{ 
     viewportwidth = document.documentElement.clientWidth, 
     viewportheight = document.documentElement.clientHeight 
} 

// older versions of IE 

else 
{ 
     viewportwidth = document.getElementsByTagName('body')[0].clientWidth, 
     viewportheight = document.getElementsByTagName('body')[0].clientHeight 
} 
document.write('<style>.desktop{ height:'+viewportheight+'px;}</style>'); 
//--> 

выходJquery/Javascript рассчитать

.desktop { height:687px;} 

но все его видовой экран. Я хочу это так: height = + viewportheight + - 30 = value. и я хочу обратиться к .desktop как этот .desktop {высота: значение;}

Обновление 1

я просто пытаюсь изменить, как это.

if (typeof window.innerWidth != 'undefined') 
{ 
     viewportwidth = window.innerWidth, 
     viewportheight = window.innerHeight, 
     height = viewportheight - 30, 
     width = viewportwidth 
} 

// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) 

else if (typeof document.documentElement != 'undefined' 
    && typeof document.documentElement.clientWidth != 
    'undefined' && document.documentElement.clientWidth != 0) 
{ 
     viewportwidth = document.documentElement.clientWidth, 
     viewportheight = document.documentElement.clientHeight, 
     height = viewportheight - 30, 
     width = viewportwidth 
} 

// older versions of IE 

else 
{ 
     viewportwidth = document.getElementsByTagName('body')[0].clientWidth, 
     viewportheight = document.getElementsByTagName('body')[0].clientHeight, 
     height = viewportheight - 30, 
     width = viewportwidth 
} 
document.write('<style>.desktop{ width:'+width+'px ;height:'+height+'px;}</style>'); 

и его работа для меня. , но если кто-нибудь здесь лучше, просто скажите мне.

+0

Пожалуйста, примите ответ или написать свой собственный ответ и принять его, чтобы указать, что проблема решена. См. [Как работает прием ответа?] (Http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – Antony

+0

О, о том, что я напишу. – Anggagewor

ответ

0

я редактировать это и свою работу для меня.

if (typeof window.innerWidth != 'undefined') 
    { 
      viewportwidth = window.innerWidth, 
      viewportheight = window.innerHeight, 
      height = viewportheight - 30, 
      width = viewportwidth 
    } 

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document) 

    else if (typeof document.documentElement != 'undefined' 
     && typeof document.documentElement.clientWidth != 
     'undefined' && document.documentElement.clientWidth != 0) 
    { 
      viewportwidth = document.documentElement.clientWidth, 
      viewportheight = document.documentElement.clientHeight, 
      height = viewportheight - 30, 
      width = viewportwidth 
    } 

    // older versions of IE 

    else 
    { 
      viewportwidth = document.getElementsByTagName('body')[0].clientWidth, 
      viewportheight = document.getElementsByTagName('body')[0].clientHeight, 
      height = viewportheight - 30, 
      width = viewportwidth 
    } 
    document.write('<style>.desktop{ width:'+width+'px ;height:'+height+'px;}</style>' 

Я не знаю о синтаксисе jquery/javascript. но я пытаюсь понять это.

я просто добавить строку

height = viewportheight - 30, 
width = viewportwidth 
0

ли вы попробовать

document.write('<style>.desktop{ height:' + (viewportheight - 30) + 'px;}</style>'); 

Я считаю, что следует вычесть 30 из viewportheight значения

+0

Я пытался попробовать эту высоту = viewportheight - 30, ее работа, но я тоже попробую. спасибо :) – Anggagewor

+0

Я думаю, что это сработает, но дайте мне знать :) – Ljubisa

+1

Я не знаю, почему, но ваш способ не работает, поэтому я пытаюсь сделать height = viewportheight -30, и я вызываю стиль, подобный этому .desktop {height : '+ height +' px;} что-то вроде этого. и работает для меня, – Anggagewor

Смежные вопросы