Jump to content

Darren

Members
  • Posts

    2
  • Joined

  • Last visited

Posts posted by Darren

  1. Thank you. Just learning Javascript now. Is there a way to elegantly add the keypress event into the current code? The left and right arrows are coded by:

     

    <button class="w3-button w3-black w3-display-right2" onclick="plusDivs(-1)">&#60;</button>

    <button class="w3-button w3-black w3-display-right" onclick="plusDivs(1)">&#62;</button>

     

    And the script:

     

    <script>
    var slideIndex = 1;
    showDivs(slideIndex);

    function plusDivs(n) {
      showDivs(slideIndex += n);
    }

    function showDivs(n) {
      var i;
      var x = document.getElementsByClassName("mySlides");
      if (n > x.length) {slideIndex = 1}    
      if (n < 1) {slideIndex = x.length}
      for (i = 0; i < x.length; i++) {
         x.style.display = "none";  
      }
      x[slideIndex-1].style.display = "block";  
    }
    </script>

  2. I have implemented the CSS/Javascript slideshow from https://www.w3schools.com/howto/howto_js_slideshow.asp with a few tweaks on a friend's portfolio site: 

    http://bradireland.com/index.html

    I've had a request to make the left and right arrows work if the user clicks the left and right arrows on their keyboard, or swipes left and right on a tablet/laptop.

    Anyone had any success with either of these? Hoping to not replace the existing code but add to it, if possible.

    Thanks!

     

×
×
  • Create New...