Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > JavaScript: для новичков > Помогите найти ошибку.


Автор: champion 4.5.2008, 08:46
Код

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
      <head>
        <style type="text/css">
                BODY {
                    height: 100%;
                    margin: 0 0 0 0;
                    padding: 0 0 0 0;
                }
                #project {
                 position: fixed;
                 background: url('png.png') green bottom center no-repeat;
                 height: 100%;
                 width: 100%;
                }
        </style>
     <script type="text/javascript">
        function setPng(obj) {
        alert(obj.style.background);
            var obj="url('image.png') right top no-repeat";
            var objArr=obj.split(" ");
            var nameFile=objArr[0];
            nameFile.replace(/\(\'/,"");
            nameFile.replace(/url/,"");
            nameFile.replace(/\'\)/,"");
        }
        function parse() {
         setPng(document.getElementById("project"));
        }
        </script>
      </head>
<body onLoad="parse()">
    <div id="project">
        test
    </div>
</body>
</html>

Почему на месте alert(obj.style.background); мне показывает пустоту? По сути код рабочий, а почему не выводит фон?

Автор: bars80080 4.5.2008, 10:26
потому как стили читаются не так, а так:
http://forum.vingrad.ru/topic-194162.html

Автор: dstorm81 4.5.2008, 10:52
http://www.tigir.com/javascript.htm

искать заголовок
Я хочу получить значение CSS свойства, но возвращается пустая строка. Например, хочу узнать цвет текста элемента и пишу document.getElementById("elemId").style.color, а результат пустая строка. Что делать?

и тщательно вкуривать smile


Автор: champion 5.5.2008, 16:48
Большое спасибо! Но проблема все же не решена. 
Пишу так
Код

            alert(obj.currentStyle.backgroundImage);

Показывает имагу, а вот когда пишу background вызывает ошибку, пробовал получить backgroundPosition не получается, говорит, что undefined.. что делать?

Автор: bars80080 5.5.2008, 17:05
может разбить единое свойство background на составляющие?

Автор: champion 7.5.2008, 07:29
Разбивал. Параметр backgroundPosition оказывается недоступным. Говорит undefined

Автор: dstorm81 8.5.2008, 10:49
Код

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
      <head>
<style type="text/css">
#project
{position:fixed;top:200px;left:0px;
height:10px;width:10px;
background:url('png.png') green; 
backgroundPosition:bottom center;
backgroundRepeat:no-repeat;}
</style>
     <script type="text/javascript">
    function getElementComputedStyle(elem, prop)
{
  if (typeof elem!="object") elem = document.getElementById(elem);
  if (document.defaultView && document.defaultView.getComputedStyle)
  {
    if (prop.match(/[A-Z]/)) prop = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
    return document.defaultView.getComputedStyle(elem, "").getPropertyValue(prop);
  }
  if (elem.currentStyle)
  {
    var i;
    while ((i=prop.indexOf("-"))!=-1) prop = prop.substr(0, i) + prop.substr(i+1,1).toUpperCase() + prop.substr(i+2);
    return elem.currentStyle[prop];
  }
  return "";
}
        </script>
      </head>
<body>
    <div id="project">qqq</div><br><br><br><br><br>
<input type="button" onclick="alert(getElementComputedStyle('project','backgroundPosition'))" value="kll" >
</body>
</html>


дальнейший гемморой с оперой оставляю за вами

Автор: SelenIT 8.5.2008, 11:34
Цитата(champion @  7.5.2008,  07:29 Найти цитируемый пост)
Параметр backgroundPosition оказывается недоступным.

Может, его тоже разбить надо -  backgroundPositionX,  backgroundPositionY?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)