Note that there are some explanatory texts on larger screens.

plurals
  1. POChange obj width and position depend on window width
    text
    copied!<p>I'm trying to make <code>box</code> width and <code>btn</code> position, change depend on <code>window width</code>.<br> Q1. How to remove <a href="http://i.imgur.com/wT443.png" rel="nofollow">white space</a> right behind the scroll bar? (I already set 100%..) <br><br> Q2. After I click <code>btn</code> 2 times back to blue one, <code>btn</code> position not same as before. How to fix it? (I set console.log to check if I click <code>btn</code> <code>window width</code> will be different, why?)</p> <p><a href="http://jsfiddle.net/JVfAd/" rel="nofollow">jsFiddle</a><br> Any suggestion will be appreciated, Thanks.</p> <pre><code>$(function(){ //set column amount var colamt=0; var winwid = $(window).width(); function setcolamt(){ winwid = $(window).width(); console.log(winwid); if(winwid &gt; 300){ if(colamt !== 8){ colamt = 6; } } console.log(colamt); }; setcolamt(); //set column width var colwid; function setcolwid(){ //set column width colwid = 100 / colamt + "%"; console.log(colwid); }; setcolwid(); //set img width function setimgwid(){ $('.box').css({width: colwid}); }; setimgwid(); // ****** button //set button postion var boxwid; function setbtnpos(){ boxwid = $('.box').width(); console.log(boxwid); $('.colamtminus').css({top: boxwid * 2}); $('.colamtplus').css({top: boxwid * 2}); }; setbtnpos(); //set button visibility when landing function visbtnchangecolamt(){ if(winwid &gt; 300){ if(colamt == 8){ $('.colamtplus').show(); $('.colamtminus').hide(); } else{ $('.colamtplus').hide(); $('.colamtminus').show(); } } }; visbtnchangecolamt(); //click button update colamt and set button visibility function setbtnchangecolamt(){ winwid = $(window).width(); $('.colamtplus').click(function(){ if(winwid &gt; 300){ colamt = 6; } setcolamt(); setcolwid(); setimgwid(); setbtnpos(); visbtnchangecolamt(); $('.colamtplus').hide(); $('.colamtminus').show(); }); $('.colamtminus').click(function(){ winwid = $(window).width(); if(winwid &gt; 300){ colamt = 8; } setcolamt(); setcolwid(); setimgwid(); setbtnpos(); visbtnchangecolamt(); $('.colamtplus').show(); $('.colamtminus').hide(); }); }; setbtnchangecolamt(); });​ </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload