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');
}
精彩评论