Вопрос по изменению кода JavaScript
Есть JavaScript, приведённый ниже, который всегда отображает баннер на странице в одном и том же заданном месте независимо от прокрутки самой страницы.
Вопрос: можно ли его изменить таким образом, чтобы по вертикали баннер отображался посередине экрана? Но тоже не зависел от прокрутки страницы. Как это сделать? <div id="divStayTopLeft" style="position:absolute"> <script type="text/javascript"> function JSFX_FloatTopLeft() { var startX = 50, startY = 100; var ns = (navigator.appName.indexOf("Netscape") != -1); var d = document; var px = document.layers ? "" : "px"; function ml(id) { var el=d.getElementById?d.getElementById(id):D.all?d.all[id]:D.layers[id]; if(d.layers)el.style=el; el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;}; el.x = startX; el.y = startY; return el; } window.stayTopLeft=function() { var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop; ftlObj.y += (pY + startY - ftlObj.y)/16; ftlObj.sP(ftlObj.x, ftlObj.y); setTimeout("stayTopLeft()", 1); } ftlObj = ml("divStayTopLeft"); stayTopLeft(); } function hiddenLayer() { NC = (document.layers); IE = (document.all); Opera = (document.getElementById); if(IE) eval('document.all["divStayTopLeft"].style.visibility = "hidden"'); if(NC) eval('document.layers["divStayTopLeft"].visibility = "hidden"'); if(Opera) eval('document.getElementById("divStayTopLeft").style.visibility = "hidden"'); } JSFX_FloatTopLeft(); </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div> |
Пробуйте заменить строку 5
var startX = 50, startY = parseInt((window.innerHeight-160)/2); Красное - высота баннера Текущее простое программное определение высоты баннера затруднено, т.к баннер - фреймом и меняет высоту в процессе загрузки |
Нет, к сожалению, не работает. Баннер отображается без учёта "Y" в том месте страницы, где указан тег DIV с кодом самого баннера.
|
Цитата:
|
В этом архиве два файла: test2 - исходный код, test3 - ваш вариант. После загрузки файлов в браузер нажмите "Ctrl + A" для наглядности. В test2 баннер при прокрутке перемещается, в test3 - нет, и рисуется не верно (не посередине экрана). Проверял в IE7 и Firefox 16.
|
RockTeam,
<!DOCTYPE HTML> <html> <head> </head> <body style="height:11800px"> <p>sddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkg hnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddd dddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5 ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjh bkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffff ffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hm vgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhka ghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddffffffffffffffffff fffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsdd ddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut8 94vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregre jhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddf ffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y 3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmh kaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffff ffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghs ddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485y ut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffreg regrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddd dddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycj mg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkg hnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddffffffff fffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh 45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghn erght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddffffffffffffffffffffff fffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddd dddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894v g3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrej hgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddf ffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8 y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgn mhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffff ffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mg hsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght48 5yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffr egregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddd dddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5y cjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhb kghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddffffff fffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvg h45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkagh nerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffff ffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddd dddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894v g3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejh gjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfff ffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3h mvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhka ghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffff ffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddd dddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut89 4vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregre jhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddf ffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3 hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhka ghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffff ffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsdddd ddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894 vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrej hgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfff ffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hm vgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkagh nerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffff ffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsdddddd ddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3 n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjh h45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkagh nerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffff ffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddd dddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894v g3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejh gjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfff ffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3h mvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhka ghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffff ffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddd dddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut89 4vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregre jhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddf ffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3 hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhka ghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffff ffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsdddd ddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894 vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrej hgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfff ffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hm vgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkagh nerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffff ffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mghsdddddd ddddddddddddfffffffffffffffffffffffffffregregrejhgjhbkghnkfgnmhkaghnerght485yut894vg3 n5ycjmg57u8y3hmvgh45mv2mghsddddddddddddddddddfffffffffffffffffffffffffffregregrejhgjh bkghnkfgnmhkaghnerght485yut894vg3n5ycjmg57u8y3hmvgh45mv2mgh</p> <div id="divStayTopLeft" style="position:absolute;z-index:1000"> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> </div> <script type="text/javascript"> function JSFX_FloatTopLeft() { var startX = 50, startY = parseInt((window.innerHeight-160)/2); var ns = (navigator.appName.indexOf("Netscape") != -1); var d = document; var px = document.layers ? "" : "px"; function ml(id) { var el=d.getElementById?d.getElementById(id):D.all?d.all[id]:D.layers[id]; if(d.layers)el.style=el; el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;}; el.x = startX; el.y = startY; return el; } window.stayTopLeft=function() { var pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop; ftlObj.y += (pY + startY - ftlObj.y)/16; ftlObj.sP(ftlObj.x, ftlObj.y); setTimeout("stayTopLeft()", 1); } ftlObj = ml("divStayTopLeft"); stayTopLeft(); } function hiddenLayer() { NC = (document.layers); IE = (document.all); Opera = (document.getElementById); if(IE) eval('document.all["divStayTopLeft"].style.visibility = "hidden"'); if(NC) eval('document.layers["divStayTopLeft"].visibility = "hidden"'); if(Opera) eval('document.getElementById("divStayTopLeft").style.visibility = "hidden"'); } JSFX_FloatTopLeft(); </script> </body> </html> |
RockTeam, этот код у вас со времен второй мировой остался?
Думаю нет смысла в нем ковыряться, проще написать все с нуля :) |
Вот оно, чудо из чудес! И ни капли скриптов! Самая что нинаесть магия!
<!DOCTYPE html><!-- с доктайпом на душе спокойнее --> <title>Тайтл</title><!-- тайтл должен быть в любом документе --> <style> body{ scrollbar-base-color: #fafafa; scrollbar-face-color: #000000; scrollbar-3dlight-color: #202020; scrollbar-arrow-color: #ffffff; scrollbar-darkshadow-color: #202020; scrollbar-shadow-color: #000000; } .wrapper{ position: fixed; top: 0; left: 0; right: 0; text-align: center; background: rgba(0,0,0,0.05); /* для наглядности */ } .banner{ display: inline-block; background: rgba(255,0,0,0.4); /* для наглядности */ padding: 30px; border: 1px solid red; } </style> <body> <div class="wrapper"> <div class="banner">Я - баннер!</div> </div> <article> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Много контента</p> <p>Контент</p> <p>Контент</p> <p>Много контента</p> </article> </body> |
if(IE) eval('document.all["divStayTopLeft"].style.visibility = "hidden"'); Ха ха, ха ха ха.. Не правильно. Нужно так: if(IE) eval("eval('document.all[\"divStayTopLeft\"].style.visibility = \"hidden\"')"); А еще лучше так: if(IE) eval('eval("eval(\'document.all[\"divStayTopLeft\"].style.visibility = \"hidden\"\')")'); Хотя нет. Можно еще лучше: хм, что то я увлекся. думаю хватит.. |
<script type="text/javascript">.. Тут тоже ошибка. Правильно так: <script type="text/necroscript"> |
Часовой пояс GMT +3, время: 04:11. |