works in chrome but not firefox - jquery

徘徊边缘 提交于 2019-12-10 22:24:49

问题


 $('#carat_weight_right li').css('left', function(index, value) {
   if (value === '100%') {

        $(this).children('span').css({'margin-left': '-58px', 'text-align': 'right'});
        alert('hello');

    }
 });

seems to work in chrome but not firefox any one have a clue ????

thanks


回答1:


This is a fun case of a cross-browser implementation difference.

Firefox is returning the used value for the element's computed style. This winds up being the actual value in pixels used to render the element in the browser: Firefox sees that 100%, decides in your layout that really equates to something like 326 pixels, and returns 326 pixels. Mozilla talks about their implementation here.

Chrome, on the other hand, returns the specified value ("100%") for the computed style.

The W3C kind of says both are valid: returning the specified value is fine if it can be done without the need for laying out the document; returning the used value is OK if that value can only be determined after layout is complete.

So what are you to do? Find a different way of making that cacluation. :-) Maybe check to see if your element's position().left is greater than or equal to its offset parent's width()?



来源:https://stackoverflow.com/questions/5941244/works-in-chrome-but-not-firefox-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!