Creating Responsive Functions: A Webflow Tutorial for Desktop and Mobile Users

Published on
November 11, 2019

Building Different Functions for Desktop and Mobile Users in Webflow

Webflow offers a great deal of flexibility for web designers and developers to create websites that are responsive and function seamlessly on both desktop and mobile devices. In this tutorial, we will walk through a step-by-step guide on how to build and implement different functions for desktop and mobile users in Webflow, without the need for code.

Setting up the Structure in Webflow

We'll start by setting up the structure of our web page in Webflow. For this demonstration, we'll create a simple web page with a button and two different text elements, one for desktop users and one for mobile users.

  1. Create Elements:
  • In the Webflow Designer, add a button and two text elements to the canvas.
  • Give the button a unique class, such as "hack-button", and the text elements distinct classes, such as "desktop-text" and "mobile-text".
  1. Styling Elements:
  • Style the button and text elements as per your design preferences, ensuring they are visually distinguishable.

With the basic structure set up, we're ready to implement the functionality to run different functions based on the screen size and device type.

Implementing Different Functions Based on Screen Size

Adding Custom Code for Custom Functionality

  1. Open the Custom Code Panel:
  • Go to the Webflow Designer and click on the "Dashboard" icon in the top-left corner.
  • Select the "Project Settings" from the dropdown menu.
  • Under the "Custom Code" tab, you'll find options to add custom code before the closing </head> tag or before the closing </body> tag.
  1. Inserting JavaScript:
  • Before the closing </body> tag, insert the following JavaScript code:
<script>  let onMobile; // Declare the variable to track if the user is on a mobile device  const resizeEvent = () => { // Function to handle the resize event    if (window.innerWidth <= 991) {      onMobile = true; // Set onMobile to true if the window size is less than or equal to 991 pixels    } else {      onMobile = false; // Set onMobile to false if the window size is greater than 991 pixels    }  }  // Run the resize event function on page load  resizeEvent();  // Listen for window resize and update the onMobile variable  window.addEventListener('resize', resizeEvent);  // Function to run when the hack button is clicked  document.querySelector('.hack-button').addEventListener('click', () => {    if (onMobile) {      // Execute the function for mobile users      document.querySelector('.mobile-text').innerText = "Hey mobile user!";    } else {      // Execute the function for desktop users      document.querySelector('.desktop-text').innerText = "Hey desktop user!";    }  });</script>

The above JavaScript code sets up an event listener to detect the click on the "hack-button" and checks whether the user is on a mobile device or desktop based on the screen size. It then updates the text accordingly.

Testing the Functionality

After inserting the JavaScript code in the custom code section, save the changes and publish your site. You can then open the live site and test the functionality of running different functions for desktop and mobile users using the button you've created.

  1. Testing on Desktop:
  • Click on the button and observe if the text for desktop users changes as expected.
  1. Testing on Mobile:
  • Resize the browser window to a width below 991 pixels (or test on an actual mobile device) and then click the button to see if the text for mobile users updates as intended.

By following these steps, you've successfully built and implemented different functions for desktop and mobile users on your website using Webflow's visual interface and custom code functionality.

Conclusion

In this tutorial, you've learned how to create and apply different functions for desktop and mobile users in Webflow. By leveraging JavaScript and Webflow's visual design capabilities, you can provide tailored experiences based on the user's device and screen size without delving into complex coding.

Remember, these methods and techniques can be further expanded and customized to suit your specific requirements, allowing you to create more interactive and adaptive web experiences for your visitors.

For additional Webflow hacks and tutorials, consider exploring more resources on the Webflow platform and subscribing to their official YouTube channel for the latest updates and releases. Additionally, you can access the full example project used in this tutorial and explore more hacks by visiting the official FinSweet website.

Whether you're a beginner or a seasoned web designer, Webflow provides a user-friendly environment for building and deploying interactive and responsive websites, empowering you to bring your creative visions to life on the web.


By following the steps outlined in this tutorial, you can effectively create and implement different functions for desktop and mobile users on your website using Webflow. With the combination of visual design and custom code capabilities in Webflow, you can enhance the user experience and engagement while ensuring seamless functionality across various devices and screen sizes. If you have any further questions or need assistance, don't hesitate to explore additional resources and support channels provided by Webflow to further refine and customize your web projects for optimal performance and user satisfaction.