Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. javascript changes values on mobile

javascript changes values on mobile

Scheduled Pinned Locked Moved General Discussion
4 Posts 2 Posters 57 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peolold
    wrote on last edited by
    #1

    hey there :)

    i've successfully implemented a "slide to unlock"-feature via some custom javascript on the frontpage of this website: https://peolold.de
    it works fine on desktop & tablet devices, hence as long as it's not the mobile version.
    i've noticed that two relevant javascript values automatically disappear when in mobile mode. i can't find a way to avoid that and it might be the reason that it doesn't work on mobile:
    jsbug_desktop.png
    <input>-tag on desktop with min & max values

    jsbug_mobile.png
    <input>-tag on mobile with missing min & max values

    does anyone have an idea why this could happen?

    1 Reply Last reply
    0
    • arminunruhA Offline
      arminunruhA Offline
      arminunruh
      Global Moderator
      wrote on last edited by
      #2

      nice!

      you use a custom phone layout. and in it, your input element doesnt have the min and max values

      you can just delete the custom phone layout
      Screenshot 2024-01-25 at 18.44.16.png

      or just change the input html in your custom phone layout to include the min and max values

      1 Reply Last reply
      0
      • P Offline
        P Offline
        peolold
        wrote on last edited by
        #3

        thanks for your quick reply!

        i use the custom phone layout on purpose for design reasons. the html-element is synched between desktop & phone layout though, so it's the exact same code. still, different code is shown when i open the website and view it via inspector.

        that's the piece of code used in both desktop & mobile:

        <div class="center-xy">
            <input type="range" value="0" class="pullee" />
        
        <script>var inputRange = document.getElementsByClassName('pullee')[0],
            maxValue = 150,
            speed = 12,
            currValue, rafID;
        
        inputRange.min = 0;
        inputRange.max = maxValue;
        
        
        function unlockStartHandler() {
            window.cancelAnimationFrame(rafID);
            
            currValue = +this.value;
        }
        
        function unlockEndHandler() {
            
            currValue = +this.value;
            
            if(currValue >= maxValue) {
                successHandler();
            }
            else {
                rafID = window.requestAnimationFrame(animateHandler);
            }
        }
        
        function animateHandler() {
            
            inputRange.value = currValue;
            
            if(currValue > -1) {
            	window.requestAnimationFrame(animateHandler);   
            }
            
            currValue = currValue - speed;
        }
        
        function successHandler() {
            var link = "https://peolold.de/portfolio";
            window.location.href = link
            
            inputRange.value = maxValue;
        };
        
        inputRange.addEventListener('mousedown', unlockStartHandler, false);
        inputRange.addEventListener('mousestart', unlockStartHandler, false);
        inputRange.addEventListener('mouseup', unlockEndHandler, false);
        inputRange.addEventListener('touchend', unlockEndHandler, false);
        </script>
        </div>
        
        1 Reply Last reply
        0
        • arminunruhA Offline
          arminunruhA Offline
          arminunruh
          Global Moderator
          wrote on last edited by
          #4

          hey please put your javascript in lay options → custom css & html

          then

          <script>…</script>

          put it in custom content for <head>

          and use https://laytheme.com/documentation/custom-javascript.html#newpage-events

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          I also code custom websites or custom Lay features.
          šŸ’æ Email me here: šŸ’æ
          info@laytheme.com

          Before you post:
          1. When using a WordPress Cache plugin, disable it or clear your cache.
          2. Update Lay Theme and all Lay Theme Addons
          3. Disable all Plugins
          4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

          This often solves issues you might run into

          When you post:
          1. Post a link to where the problem is
          2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
          3. If the problem is difficult to explain, post screenshots / link to a video to explain it
          Online Users
          Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
          laytheme.com
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Recent
          • Tags
          • Popular
          • Users
          • Search