Note that there are some explanatory texts on larger screens.

plurals
  1. POJava script - Keep buttons hidden until page load
    primarykey
    data
    text
    <p>I have built a horizontal scrolling website. I don't really know much about Java Script, but I downloaded this script called Horizontal Tiny Scroller that lets you scroll the website horizontally, without using the scroll bar.</p> <p>Everything works perfectly except the script only loads once everything else on the page has finished loading. As my site has a high number of graphics, this creates a usability as the scroller buttons do not immediately work. I'm guessing most the users will assume that the buttons are broken.</p> <p>After a bit of research I have found that there is no solution to making the buttons load before the graphic, so I will just have to hide the buttons until the page has loaded.</p> <p>The Tiny Scroller script uses a document.writeln command to make the buttons appear on the page:</p> <pre><code>document.writeln('&lt;a href="javascript://" id="left-arrow"&gt;&lt;/a&gt;\n&lt;a href="javascript://" id="right-arrow"&gt;&lt;/a&gt;'); </code></pre> <p>Using online tutorials, I created two CSS classes: <code>.visible {display:block;}</code> <code>&amp; .hidden {display:none;}.</code> I rewrote the <code>document.writeln</code> command so the buttons were assigned the <code>.hidden</code> class by default:</p> <pre><code>document.writeln('&lt;a href="javascript://" id="left-arrow" class="hidden"&gt;&lt;/a&gt;\n&lt;a href="javascript://" id="right-arrow" class="hidden"&gt;&lt;/a&gt;'); </code></pre> <p>Finally, I wrote an <code>onload=function</code> to swap the <code>.hidden</code> class with the <code>.visible</code> class:</p> <pre><code>onload=function() { document.getElementById('left-arrow').className='visible'; document.getElementById('right-arrow').className='visible'; } </code></pre> <p>The finished script can be seen <a href="http://olo.uk.com/sites/all/themes/olotheme/scripts/body-scroller.js" rel="nofollow noreferrer">here</a></p> <p>Everything works fine, and the buttons only appear when the page has loaded. HOWEVER, the scrolling function doesn't work any more! If I delete the <code>onload=function</code> everything works again (but then of course the buttons appear before the page has finished loading).</p> <p>Does anyone have any pointers as to what I'm doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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