javascript - Loading images from different folders -
so want load different images different folders. have little puzzle can change format example 3x3, 3x4, 4x3 , 4x4 etc. , want when clicks on "select format" , choose 3x3 loads images 3x3 folder , if clicks on 4x4 want images 4x4 folder.
the folder looks /images/3x3/1.png or /images/4x4/1.png. right pictures loading same folder. ideas how fix that? tried making new variable , using if statement chose different folders didnt work.
here code better understanding:
code: http://jsfiddle.net/cuttingtheaces/vkyxgwo6/19/
the part folders should changed because right uses images folder images:
function changeformat(x, y) { var puzzlepieces = []; var finalvalue = x * y - 2; (var = 0; <= finalvalue; ++i) { puzzlepieces.push(i); } puzzlepieces.push('blank') createslidingpuzzle(puzzlepieces, x, y); } function createslidingpuzzle(puzzlepieces, x, y) { var puzzle = '<div id="slidingpuzzlecontainer' + x + 'x' + y + '">'; cols=x; puzzlepieces=shuffle(puzzlepieces); (var puzzlenr = 0; puzzlenr < puzzlepieces.length; ++puzzlenr) { puzzle += '<img src="images/' + puzzlepieces[puzzlenr] + '.png" class="puzzlepiece" id="position' + puzzlepieces[puzzlenr] + '" alt="' + puzzlepieces[puzzlenr] + '" onclick="shiftpuzzlepieces(this);" width="100" height="100" />'; } puzzle += '</div>'; showslidingpuzzle(puzzle); }
many in advance.
if want have url image in format like: "/images/3x3/1.png" have change line of code:
puzzle += '<img src="images/' + puzzlepieces[puzzlenr] + '.png" class="puzzlepiece" id="position' + puzzlepieces[puzzlenr] + '" alt="' + puzzlepieces[puzzlenr] + '" onclick="shiftpuzzlepieces(this);" width="100" height="100" />';
to
puzzle += '<img src="images/' + x + 'x' + y + '/' +[puzzlenr] + '.jpg" class="puzzlepiece" id="position' + puzzlepieces[puzzlenr] + '" alt="' + puzzlepieces[puzzlenr] + '" onclick="shiftpuzzlepieces(this);" width="100" height="100" />';
here working example forked of version: jsfiddle. if inspect img elment can see has source this
src="images/3x3/4.jpg"
Comments
Post a Comment