Turn off jQuery for mobile devices

I need assistance in modifying a script that causes a fade effect on certain elements only on desktop and not on mobile devices. I have attempted using the code below, but it seems to hide all elements on all screen resolutions. In my CSS, I am applying display: none to each element, and I suspect that when the jQuery script is disabled, the CSS takes over. I'm unsure of how to resolve this issue. Any guidance would be greatly appreciated!

var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;

$(window).load(function() {
if(!isMobile) {
$('.rmm').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
$('.social').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
 $('.filmpress').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
 $('.filmpress2').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
$('.arrow').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
$('.venice').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
  $('.title').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
 $('.logo h3').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
$('#bgbig').each(function(i) {
  $(this).delay((i + 0) * 250).fadeIn(1000);
});
$('.logo h2').each(function(i) {
  $(this).delay((i + 4) * 250).fadeIn(1000);
});
}
});

Answer №1

One way to optimize your code is to combine all the selectors into a single function. Additionally, if the elements have a default style of display: none, you may need to use show() to display them when accessed from a mobile device. Here is an example of how you can achieve this:

var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ? true : false;

$(window).load(function() {
    var $elems = $('.rmm, .social, .filmpress, .filmpress2, .arrow, .venice, .title, .logo h3, #bgbig, .logo h2');
    if (isMobile) {
        $elems.show();
    }
    else {
        $elems.each(function(i) {
            $(this).delay((i + 4) * 250).fadeIn(1000);
        });
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I create a loop to iterate through form/input files with varying titles?

Looping through input files with different titles Hello, I am trying to figure out how to loop through an input file with different titles. Each input file has a unique title, such as Safety Data Sheet, Certificate, etc. This is my current code: $titles ...

Learn how to insert JavaScript code into the head of an iframe using jQuery

My goal is to inject javascript code into the head of an iframe using jquery with the code provided below. var snippets_js='<?php echo $snippets_javascript;?>'; var scriptjs = document.createElement("script"); scriptjs.type = "text/j ...

The JavaScript code malfunctions when I introduce a new HTML tag

I am attempting to create a simple photo gallery using PhotoSwipe. However, I have encountered an issue where certain functions like Previous and Next buttons stop working when I add new HTML elements. Here is the original code: <div class="my-gallery ...

Ensure the background image is optimized for viewing on screens of any size

I am facing an issue with an image on my website that serves as the background for some elements. The image is wider than it is tall, causing problems for users viewing the site on phones. Is there a way to cut off the sides of the image and ensure it fits ...

How can I retrieve the values of jQuery select2 tag list in ASP.NET?

I am looking to retrieve the selected values from the jQuery Select2 plugin in my ASP.NET code behind. Below is a snippet of my code: Client Side: <select id="ddlcountry" runat="server" class="select" style="width: 100%;"> ...

Conceal YouTube upon opening any model or light box

I have a YouTube video in the center of my page, and when I click on any link from the side navigation, a lightbox appears. However, in IE, the lightbox is behind the YouTube video. I have tried setting the Z-index, but it doesn't seem to work. Is the ...

What strategies can be used to effectively combine Server-side postbacks with jquery's animations?

My ultimate goal is to create something that surprises me every time: I am in the process of developing an application in the same way I always have: using some <asp:LinkButtons> (or regular buttons), displaying content in Panels with <asp:Updat ...

Getting the Kendo UI AutoComplete value onKeyUp within a ViewModel: A step-by-step guide

I'm facing an issue with the Kendo UI AutoComplete. I need to capture the value as the user types in order to send a query to the server for result filtering. The change event only triggers onBlur and not on keyup/down/press events. Additionally, the ...

Expanding CSS Grid to Occupy Remaining Area

I'm currently utilizing CSS grid to construct a basic 3 column layout. Here's a snippet of my code... .container { display:grid; grid-template-columns:1fr 1fr 1fr; } ...

Enhance your webpage design with stylish CSS formatting using Bulma cards

My HTML output is as follows: https://i.stack.imgur.com/aBdEF.jpg It seems that the footer is not matching up with the cards... The CSS component I am using looks like this: .card-equal-height { display: flex; flex-direction: column; height: 100%; ...

Implementing jQuery during the navigation between Node routes

Below is a snippet of my jQuery code: $(function () { $('.mnav a').click(function () { el = $('.border'); el.addClass('blink'); el.one('webkitAnimationEnd oanimationend msAnimationEnd animatio ...

What steps can I take to maintain the width while implementing jQuery's slideUp function?

I am facing a scenario where: http://www.jsfiddle.net/kPBbb/ After adding content to .content, the .wrapper shrinks itself, possibly due to the fact that the .content is set to display: none. I want the .wrapper to maintain its original size even after t ...

Replace the content within the iFrame completely

Is it possible to have a textarea where I can input HTML code and see a live preview of the webpage in an iframe as I type? For example, here is the code I'd like to write in the textarea: <!DOCTYPE html> <html> <head> ...

jwplayer - track viewing time - monetize by the minute - trigger action based on duration

My goal is to track the time duration that someone watches a video, ideally by triggering an action every minute. I'm aiming to create a pay-per-minute system where a credit is withdrawn from the user for each minute they watch. If this setup isn&apo ...

Altering the JavaScript variable by selecting an option from a dropdown list

After downloading a choropleth map from leafletjs.com, I encountered an issue with multiple JS files labeled by year (e.g. us-states2012.js, us-states2013.js). The challenge now is to implement a drop down menu in such a way that selecting a specific year ...

The gif loader persists even after subscribing

Looking to incorporate the SendGrid subscription widget into my site, but struggling with the implementation. The code provided by SendGrid is partially functional - the loader appears and a success message is displayed upon sign up, but the GIF loader doe ...

Issue with AJAX MVC HTML: jQuery value is not blocking API call

Upon clicking a button, I am triggering a web API call using AJAX. My form is utilizing JqueryVal for form validations based on my viewmodel data annotations. The issue I am facing is that when I click the "Listo" button in my form, it executes the API ca ...

Ways to exhibit API information leveraging the prowess of Ajax

I am looking for a way to utilize the API in order to present data in an organized manner, similar to the following example: Job Title: Agricultural and Related Trades Percentage of Occupancies in Area: 15.41% Unfortunately, my attempt to showcase the d ...

What is the best way for me to insert a paragraph between two lists?

Is it possible to insert a paragraph in between lists even though it's not allowed? Here is an example of the code: <ol> <li>One</li> <p>Paragraph 1</p> <li>Two</li> <p>Paragraph 2</p ...

Filtering data from an array in PHP

I have a code snippet that functions well when the target variable is a single value. The assumption here is that $bank_country represents a single value, such as Brazil, with no issues. <select class="form-control" multiple="1" name="country[]"> & ...