开发者

jQuery - if statment, combined widths minus 100 must be less than body

The following code checks the combined width of a set of divs, and if there less wide than the document body it changes the ID of a different div:

$(document).ready(function() {
$('#makeMeScrollable').each(function() {
var totalImageWidth = 0;

$(".image-div", this).each(function () {
  totalImageWidth += $(this).width();
});

if (totalImageWidth < $(document.body).width() ) {
   $(this).attr('id', 'm开发者_开发百科akeMeScrollable2');
}

});
});

How can I change it so the combined width minus 1000px needs to be narrower than the body for the same thing to happen? Ive tried the following:

if (totalImageWidth - 1000 < $(document.body).width() ) {

Thanks


Try this

if ((totalImageWidth - 1000) < $(document.body).width() ) {
   $(this).attr('id', 'makeMeScrollable2');
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜