简体   繁体   中英

unexpected identifier error in jquery

Whats wrong with this jquery?

$(function(){
    totalwidth = $(window).width();
    if ( totalwidth < 1295 ){
        $("#maininvite").width(((1295 - totalwidth)x100 / 1295) + 50 +'%');
    }

});

the purpose of it is to make the calculations and then add it to the already set width of 50%.

it gives me unexpected identifier in the chrome inspect

Looks like this line is your issue

x100

supposed to be

*100

Better calculate the value and then concatenate to the '%'

$(function(){
    totalwidth = $(window).width();
    if ( totalwidth < 1295 ){
        var newWidth =  (((1295 - totalwidth) * 100)/1295 ) + 50; 
        $("#maininvite").width( newWidth + '%');
    }

});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM