Jquery / Javascript рассчитать

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

выход

.desktop { height:687px;}

но его все окна просмотра. Я хочу это так: height = + viewportheight + - 30 = value. и я хочу применить к.desktop, как этот.desktop {height: value;}

Обновление 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
    Пожалуйста, примите ответ или напишите свой собственный ответ и примите его, чтобы указать, что проблема решена. См. Как работает принятие ответа?
  • 0
    о, жаль, я напишу это.
Теги:

2 ответа

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, его работа, но я тоже попробую. Спасибо :)
  • 0
    Я думаю, что это будет работать, но дайте мне знать :)
Показать ещё 2 комментария

Ещё вопросы

Сообщество Overcoder
Наверх
Меню