Hi everyone,I''m trying to build a simple dropdown menu for a website and i need toneed a way to retrievethe top and left style attributes of an object. However it seems styleattributes like style.topa not always available, depeding, i think, on whether the object inquestion is positioned relatively or absolutely.I''ve been able to use event.pageX and event.pageY with some success,but it''s not really apropriatefor what i wan''tMSIE used to have pixelTop which returned a numerical value and alsothe renderStyle which would return the calculated style value of aauto layouted object, but nothing like this available in firefox and Iassume it isn''t standard.dhtml anyway.What is the recommeded (and fool-proof) way to get the x, y co-ordinates in javascript using standardnon-browser specific dhtml?I appreciate any feedback you might have on this.- Jens 解决方案 ??lvaro G. Vicario wrote:Jens escribi?3:>I''m trying to build a simple dropdown menu for a website and i need toneed a way to retrievethe top and left style attributes of an object. However it seems styleattributes like style.topa not always available, depeding, i think, on whether the object inquestion is positioned relatively or absolutely.[...]>What is the recommeded (and fool-proof) way to get the x, y co-ordinates in javascript using standardnon-browser specific dhtml?The only foolproof way I know is using a framework: jQuery, mootools,prototype... They all offer functions to calculate any element size andposition and they''ve been tested in several browsers.ROTFL. They have been only tested in the latest versions of a few browsersthat their rather clueless developers had available (did you notice that itis not even mentioned on which platforms the tests that attempt to assure usof their quality were performed?). And they are poorly written in the firstplace (using browser sniffing and making other ridiculous blunders), so thembeing tested as working may as well be sheer coincidence.We have discussed that ad nauseam here before (with no substantial rebuttalof the criticism from their developers), and you are well-advised not to usethem and not to recommend them as well.PointedEars--Anyone who slaps a ''this page is best viewed with Browser X'' label ona Web page appears to be yearning for the bad old days, before the Web,when you had very little chance of reading a document written on anothercomputer, another word processor, or another network. -- Tim Berners-LeeThomas ''PointedEars'' Lahn escribi?3:>>non-browser specific dhtml?The only foolproof way I know is using a framework: jQuery, mootools,prototype... They all offer functions to calculate any element size andposition and they''ve been tested in several browsers.ROTFL. They have been only tested in the latest versions of a few browsersthat their rather clueless developers had available (did you notice that itis not even mentioned on which platforms the tests that attempt to assure usof their quality were performed?). And they are poorly written in the firstplace (using browser sniffing and making other ridiculous blunders), so thembeing tested as working may as well be sheer coincidence.We have discussed that ad nauseam here before (with no substantial rebuttalof the criticism from their developers), and you are well-advised not to usethem and not to recommend them as well.Interesting: all existing frameworks are so terrible that any snippet ofcode written by a newbie will have a far superior browser compatibility.The only problem is that I couldn''t care less about your opinions, Mr.All Developers Suck Except Me, and I''m pretty sure I''m not the only one.If your strong opinions about everything normally remain undisputed I''ddare say it''s because nobody likes to discuss with you: you tend tocriticize the person when you don''t like the opinions and you seem tothink JavaScript is a religion subject to dogma.*plonk*---- http://alvaro.es - ??lvaro G. Vicario - Burgos, Spain-- Mi sitio sobre programaci?3n web: http://bits.demogracia.com-- Mi web de humor al ba?±o Mar?*a: http://www.demogracia.com--=?UTF-8?B?IsOBbHZhcm8gRy4gVmljYXJpbyI=?= wrote on 23 jul 2008 incomp.lang.javascript:Thomas ''PointedEars'' Lahn escribi?3:>>>non-browser specific dhtml?The only foolproof way I know is using a framework: jQuery,mootools, prototype... They all offer functions to calculate anyelement size and position and they''ve been tested in severalbrowsers. ROTFL. They have been only tested in the latest versions of a fewbrowsers that their rather clueless developers had available (did younotice that it is not even mentioned on which platforms the teststhat attempt to assure us of their quality were performed?). Andthey are poorly written in the first place (using browser sniffingand making other ridiculous blunders), so them being tested asworking may as well be sheer coincidence.We have discussed that ad nauseam here before (with no substantialrebuttal of the criticism from their developers), and you arewell-advised not to use them and not to recommend them as well.Interesting: all existing frameworks are so terrible that any snippetof code written by a newbie will have a far superior browsercompatibility.The only problem is that I couldn''t care less about your opinions, Mr.All Developers Suck Except Me, and I''m pretty sure I''m not the onlyone. If your strong opinions about everything normally remainundisputed I''d dare say it''s because nobody likes to discuss with you:you tend to criticize the person when you don''t like the opinions andyou seem to think JavaScript is a religion subject to dogma.*plonk*Dear friend, I never saw a religion that was not subject to dogma,your dogma seems to be that you do not like to hear voices thatcontradict your opinions, and so killfiling dear Pointed.That will not flatten his ears or stop him from uttering his meaning, forthis is usenet, but it shows your own sectarianism, to keep yourreligious analogy.btw, [OT] for [off topic] on usenet does not mean you change the subject,but that the subject at hand is not a subject allowed by charter for aNG. Wrongly added in this case by you.==========Pointed''s ROTFL seems to me in response to your "foolproof"in "The only foolproof way I know is using a framework".I think here he is completely right, [but for the fact that rolling overthe floor could harm his ears], because those libraries are certainly notfoolproof, you would be a fool not to take that into account.And not using the libraries and doing the hard work yourself will giveyou not only more satisfaction and enhance your learning curve, but theknowledge that your code does what you wanted it to do, at least on theplatforms you extensively tested.--Evertjan.The Netherlands.(Please change the x''es to dots in my emailaddress) 这篇关于火狐定位。替换MSIE像pixelToppixelWidth renderStyle的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 17:14