javascript - jQuery issues with the 'this' modifier and if/else statement -
ok, i'm trying make image can modified or moved in browser clicking on buttons on side of page, script in if/else statement isn't working i'd to. here's have far in jquery:
<meta charset="utf-8"> <title>image mod</title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="js/main.js"> var menu = $('ul li').click(function() { console.log($(this).index()); if (menu = 0) { $('this').css('width', '80%') } else if (menu = 1) { $('this').css('height', '80%') } else if (menu = 2) { $('this').css('height', '80%') } else if (menu = 3) { $('this').css('top', '30') } else if (menu = 4) { $('this').css('left', '50') } else if (menu = 5) { $('this').css('left', -50') } else { } }); </script> </head> <body> <nav id="sidebar"> <ul> <li>edit 1</li> <li>edit 2</li> <li>edit 3</li> <li>edit 4</li> <li>edit 5</li> <li>edit 6</li> </ul> </nav> <img class="active" src="images/picture.jpg" /> </body>
$('this') selector <this> tag.
change $(this)
in if statements, single = assignment , evaluate true if value on right non-zero. need use == test equality. should consider switch statement, so:
switch ($(this).index()) { case 0: // stuff break; case 1: // more stuff break; default: // no other match }
Comments
Post a Comment