javascript - $(element).width() reports differently values on Safari mobile -
i'm using script total width of horizontal div:
$(document).ready(function(){ $('.portfolio li').each(function(index) { totalwidthportfolio += parseint($(this).width(), 10) + 12; }); $('.portfolio').css({ 'width' : totalwidthportfolio , 'visibility' : 'visible' }); });
the problem on desktop, script returned 23406 , on mobile (safari , chrome), returned 22522.
i tried outerwidth(true)
result same.
here css:
.portfolio{ margin: 0; padding: 0; list-style-type: none; position: absolute; top: 50%; transform: translatey(-50%); visibility: hidden; } li{ float: left; padding-right: 12px; display: block; box-sizing: border-box; } li img{ display: block; max-width: 100%; height: auto; }
update
the problems occurs on portrait mode
the value returned depends how browser parse yours li element. try add display: block properties on css
Comments
Post a Comment