What is the best way to conceal a bootstrap directive tooltip in Vue.js for mobile users?

Currently, I'm tackling a project with Vuejs and Laravel.

There's a tooltip directive incorporated that relies on Bootstrap's functionality.

Check it out below:

window.Vue.directive("tooltip", function(el, binding) {
  // console.log(el, binding);

  window.$(el).tooltip({
    title: binding.value,
    placement: binding.arg ? binding.arg : "right",
    trigger: "hover",
    html: true
  });
});

To use it:

<div
            v-tooltip="messages.type_button"
            class="form-group row border-bottom p-2"
          >

Where you define the messages object as follows:

message:{
type_button:'Hello World, this is tooltip'
}

Although the tooltip functions well on desktops, it presents display issues on mobile devices. Therefore, the decision is to hide the tooltip on mobile.

Given the absence of any identified package, it seems likely that this is a custom directive created specifically for this project.

We attempted using media queries to hide the tooltip on mobile but encountered no success. Any suggestions on how to approach this issue would be greatly appreciated.

Answer №1

After much searching, I finally came across the solution thanks to Umezo's insightful comment

Here is the code snippet that did the trick:

window.Vue.directive("tooltip", function(el, binding) {
  // console.log(el, binding);

    if (window.matchMedia("(min-width: 300px)").matches) {

        window.$(el).tooltip({
            title: binding.value,
            placement: binding.arg ? binding.arg : "right",
            trigger: "hover",
            html: true
        });
    }
});

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

Strategies for resolving the Uncaught (in promise) DOMException: Failed to load due to unsupported source in Vue + Node error

I am currently developing a web application that takes speech input and converts it into text. This text is then sent to OpenAI (ChatGPT) for generating an answer, and AWS Polly is used for voice output when ChatGPT returns a response. However, I am facin ...

Are third-party scripts and HTML widgets able to replicate your website's data, including cookies, HTML, and other elements?

Currently, I am in the process of constructing a website that incorporates a third-party weather HTML widget. The widget is sourced from a trusted and reliable source on the web. It consists of a link and small JavaScript tags that are executed once loaded ...

Tips for refreshing a specific div element at set intervals using JQuery AJAX?

I need to make updates to a specific div element without refreshing the entire HTML page. The code below currently works, but it reloads the entire HTML page. Additionally, I am working with different layouts where I have separate files for the header, l ...

Is it possible that data scraping with puppeteer consistently retrieves information solely from the initial page?

I'm facing an issue while trying to extract data from a website using puppeteer. Whenever I make a request for data, it always returns the information from the first page, even if I specify a different URL. Strangely, when I manually search for the sa ...

Adding LocalStorage functionality to buttons in order to switch colors can be done by storing the

I've run into an issue trying to incorporate LocalStorage with the buttons that change colors as themes in JavaScript. I'm new to coding and eager to add this feature to my personal blog. $(document).ready(function () { $(".header--theme-button ...

The PHP page is not receiving the variable passed through AJAX

Within the following code snippet, there seems to be an issue with accessing the dataString variable in the comment.php page. To retrieve the variable name, I utilized $_POST['name']. $(document).ready(function(){ $("#submit").click( function() ...

Implementing dynamic checkbox values depending on a selection from a dropdown menu in Angular

In my checkbox list, I have various Samsung mobile models and two offers available. $scope.offers = [ { id: "as23456", Store: "samsung", Offer_message:"1500rs off", modalname: "Samsung Galaxy You ...

Tips on how to align bullet points in a list

I'm currently working on a little exercise that requires me to replicate this However, I'm facing some difficulty aligning the bullets as shown in the reference. My content is aligned but not the bullets. Here's the link This is my HTML: ...

Aligning text in a vertical progress bar using absolute positioning

Currently, I am trying to create a health bar-like element but I am facing difficulties in centering the text within it. Despite exhausting all my options, the text is either off-center when its length changes or extends beyond the borders of the bar. Her ...

Customizing Material UI: Grouping Tab components within a div container

How can I wrap the children of a Material UI Tabs component in divs? <Tabs value={value} indicatorColor="primary" textColor="primary" onChange={handleChange} > <div> <Tab label="x" /> ...

What is the best way to integrate a backend with the webpack template?

Recently diving into Vue.js and Webpack, I have decided to utilize the webpack template provided by vue-cli for my new project. Now that I have generated this project, I am interested in incorporating a backend system. I'm wondering if it would be wi ...

Guide on hiding the sidebar in mobile view and enabling toggling on click for both mobile and other devices with the use of vue.js and bootstrap4

I need assistance with transitioning my code from pure Bootstrap4 and JavaScript to Vue.js. When I tried implementing it in mobile view, the sidebar is not showing. Below is the code snippet that I am trying to change for Vue.js, but I keep encountering an ...

Promise disregards the window being open

I'm facing an issue with redirecting users to Twitter using window.open in a specific function. It seems like the instruction is being ignored, even though it works perfectly on other pages. Any ideas on how to fix this? answerQuestion() { if ...

Disabling an HTML attribute on a button prevents the ability to click on it

In my React application, I have a button component that looks like this: <button onClick={() =>alert('hi')} disabled={true}>test</button> When I removed the disabled attribute from the browser like so: <button disabled>test& ...

Upgrading to React Router v6: Implementing Loader Functions with Context API

Having issues implementing loaders in React-Router V6 while making a request for a page through a function located in the context file. Unfortunately, I can't access the context from main.js where the router is defined. Main.js import ReactDOM from & ...

Express router fails to mount

Struggling with my first project using expressjs, I have encountered an issue with a router not properly mounting. My approach involves the app mounting a router object which should then mount a second router object. While the first embedded router mounts ...

Conceal a particular object from view by selecting it from the menu

I want to hide a specific element when the burger button is clicked. (See CaptureElementNoDisplay.PNG for the element to hide) When I click the burger button again to close the menu, I want the hidden item to be displayed once more. I've successfull ...

What is the method to assign a value to ng-class in Angularjs?

I need to categorize items in a list by assigning them classes such as items-count-1, items-count-2, items-count-3, items-count-4, based on the total number of items present. This is how I would like it to appear: li(ng-repeat="area in areas", ng-class=" ...

The event is being triggered on two separate occasions

Hey there! I'm trying to bind the onclick event to both a parent and child element using the same method. However, I'm running into an issue where the event is being fired twice. Any suggestions on how to prevent this from happening? <div id= ...

Is there a way to retrieve the checked value from a checkbox stored in a database using Vue.js components in conjunction with Laravel?

Is there a way to retrieve the selected checkbox value from the database within a Vue.js component integrated with Laravel? How can the issue with the edit.vue component be resolved in order to determine if the checkbox is checked or unchecked? Another c ...