Что не так в скрипте
function showHint(show,text){
if(show==true){
var obj=document.getElementById('hint');
obj.style.position='fixed';
obj.style.left=window.clientWidth;
obj.style.top=window.clientHeight;
window.status='x-'+obj.style.left+';y-'+obj.style.top;
obj.innerHTML=text;
}
else{
document.getElementById('hint').innerHTML='';
}
}
<div id="hint" style="width:150px;background-color:#000000;color:#ffffff;"></div> Должен вывести этот див в правый нижний угол экрана. Но не выводит. Что не так? |
Вот пример
<script type="text/javascript">
if(show==true){
var obj=document.getElementById('hint');
obj.style.position='fixed';
obj.style.left=window.clientWidth;
obj.style.top=window.clientHeight;
window.status='x-'+obj.style.left+';y-'+obj.style.top;
obj.innerHTML=text;
}
else{
document.getElementById('hint').innerHTML='';
}
}
</script>
<span onmousemove="showHint(true,'DELPHI');" onmouseover="showHint(false,'');">DELPHI</span>
<div id="hint" style="width:150px;background-color:#000000;color:#ffffff;"></div>
[/html] |
Единицы измерения допишите.
|
Попробовал изменить JS и HTML
Тиак:
function showHint(show,text){
if(show==true){
var obj=document.getElementById('hint');
var temp=new Integer();
temp=document.body.clientWidth-150;
obj.style.left=temp.toString()+'px';
temp=document.body.clientHeight-150;
obj.style.top=temp.toString()+'px';
obj.innerHTML=text;
}
else{
}
}
<div id="hint" style="width:150px;float:right;background-color:#000000;color:#ffffff;position:absolute;"></div> |
Цитата:
obj.style.left = window.clientWidth + "px"; только window.clientWidth хз где будет работать, в некоторых браузерах есть window.innerWidth, в других надо ширину documentElement или body определять. Измерения окна, документа и элементов _ |
Всё нашёл тут нужную стаью.
Перенастроил так JS и HTML <div id="hint" style="width:150px;float:right;background-color:#000000;color:#ffffff;position:absolute;"></div>
function showHint(show,text){
if(show==true){
var obj=document.getElementById('hint');
var temp=0;
temp=document.body.clientWidth-150;
obj.style.left=temp.toString()+'px';
temp=document.body.clientHeight-150;
obj.style.top=temp.toString()+'px';
obj.innerHTML=text;
window.status='x='+obj.style.left+'y='+obj.style.top;
}
else{
}
}
По идее исходя из статьи скрипт посчитает ширину и высоту всего дока. Тк DOCTYPE нагло скоировал с этой статьи, т.е. Цитата:
|
P.S. Короче опера несмотря не на что этот доктайп игнорирует как и ишак
|
Все браузеры переходят в Standards Compliance Mode c указанным доктайпом XHTML 1.0, вы что-то делаете неправильно.
И toString, при сложении числа со строкой, делать не нужно, сработает приведение типов, это основы JavaScript… |
Проверю
|
Ни один XHTML DOCTYPE который мне известен (Strict (строгий), Transitional (переходный), Frameset (с фреймами)) не работает.
Вот они сами <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> |
что не работает то?
|
Несмотря на то что написано в статье скрипт определяет не ширну/высоту клиента, а ширину/высоту документа
|
Window size and scrolling
(function alertSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );
}());
|
Спс, помогло
|
| Часовой пояс GMT +3, время: 19:23. |