Dynamic JQuery Tooltip Animation

I am trying to select a style from the dropdown menu and have the tooltip animate in the selected way. However, my tooltip is always behaving the same. Could the issue be with the 'show:' property or am I not getting the correct value of the style? Should I consider using the change() function?

Check out this link for reference

 <script>
  $(function() {
        var value=$( "#effect" ).val();
    $( document ).tooltip({
      show: {
        effect: value,
        delay: 50
      },
      position: {
        my: "center bottom-20",
        at: "left top",
        using: function( position, feedback ) {
          $( this ).css( position );
          $( "<div>" )
            .addClass( "arrow" )
            .addClass( feedback.vertical )
            .addClass( feedback.horizontal )
            .appendTo( this );
        }
      }
       });
  });
  </script>

</head>
<body >


 <div style="width:400px; margin:100px auto;">
 <select id="effect">
 <option value="blind">Blind</option>
  <option value="bounce">Bounce</option>
  <option value="clip">Clip</option>
  <option value="drop">Drop</option>
  <option value="explode">Explode</option>
  <option value="fade">Fade</option>
  <option value="fold">Fold</option>
  <option value="highlight">Highlight</option>
  <option value="puff">Puff</option>
  <option value="pulsate">Pulsate</option>
  <option value="scale">Scale</option>
  <option value="shake">Shake</option>
  <option value="size">Size</option>
  <option value="slide">Slide</option>
  <option value="transfer">Transfer</option>
  <option value="myAnimation">My animation</option>
  </select>
  <br/><br/>
 <div style="width:100px">Име:</div><input id="ime" class="tooltip" name="ime" style="width:200px" title="Име"/>

 </div> 

Answer №1

Check out this solution: http://jsfiddle.net/alemarch/2n5k6kwn/2/

  $(function() {
     $("#effect").change(function(){
        $( document ).tooltip({
          show: {
            effect: $( "#effect" ).val(),
            delay: 50
          },
          position: {
            my: "center bottom-20",
            at: "left top",
            using: function( position, feedback ) {
              $( this ).css( position );
              $( "<div>" )
                .addClass( "arrow" )
                .addClass( feedback.vertical )
                .addClass( feedback.horizontal )
                .appendTo( this );
            }
          }
        })
     })
  });

Answer №2

Upon page load, you are selecting a value and using it as the tooltip throughout. Additionally, all tooltips on the page are being changed simultaneously by attaching an event listener at the document level.

To ensure proper functionality, update your code as follows:

$( '#ime' ).tooltip({
  show: {
    effect: $( "#effect" ).val(),
    delay: 50
  },
  position: {
    my: "center bottom-20",
    at: "left top",
    using: function( position, feedback ) {
      $( this ).css( position );
      $( "<div>" )
        .addClass( "arrow" )
        .addClass( feedback.vertical )
        .addClass( feedback.horizontal )
        .appendTo( this );
    }
  }
});

It would be even more efficient to update the 'value' variable every time the dropdown selection changes. This way, jQuery won't need to repeatedly search for the value when a tooltip is triggered.

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

Preventing direct calls to a remote ColdFusion function through AJAX: A step-by-step guide

In my Coldfusion server, I manage multiple applications that all utilize a common set of component functions for both server-side rendering and AJAX requests. This shared component file is named: serverfunctions.cfc While these functions are stored separ ...

What is the best way to position the button in line with multiple dropdown menus that include labels?

My interface consists of 3 dropdowns and a submit button, each with a label. Initially, I struggled to align the button with the dropdowns themselves (not the labels), so I resorted to adding a placeholder label and matching its color with the background. ...

Challenges arising from utilizing distinct list style types for both parent and child elements with the assistance of CSS List

I am experimenting with the CSS counter reset feature to create a numbering system on my website. The main list should be in regular decimal format (e.g. 1, 2, 3, 4) while the sub-list should be in upper Roman numerals (e.g. I, II, III, IV, etc). Below is ...

Utilize the alignment capabilities of the Bootstrap framework or any other suitable plugin for

I am trying to dynamically display my div's similar to the image below. I am not able to find a solution for this problem on SO or Google yet. https://i.sstatic.net/0QcfF.jpg .box { width: 25%; height: auto; float: left; } .box-1 { backgr ...

Go to a different webpage containing HTML and update the image source on that particular page

I am facing an issue with my html page which contains multiple links to another page. I need to dynamically change the image references on the landing page based on the link the user clicks. The challenge here is that the link is inside an iframe and trigg ...

How can you capture the VIRTUAL keyCode from a form input?

// Binding the keydown event to all input fields of type text within a form. $("form input[type=text]").keydown(function (e) { // Reference to keyCodes... var key = e.which || e.keyCode; // Only allowing numbers, backspace, and tab if((key >= 48 && ke ...

Exploring the bind() method in the latest version of jQuery,

After upgrading my JQuery version, one of the plugins I was using stopped working. Despite trying to use the migrate plugin and changing all instances of bind() to on(), I still couldn't get it to work properly. The plugin in question is jQuery Paral ...

What is the reason behind the optional assignment of "window.$ =" in Vue.js imports, but mandatory for jQuery in JavaScript files?

There is an interesting behavior I've observed when using the "require" function with Vue versus jQuery. With Vue, I have found that the following statement structures work seamlessly in my application: window.Vue = require('vue'); window.$ ...

Is it possible to utilize both jQuery and AngularJS in our web application?

Is it feasible to incorporate both jQuery and AngularJS in our web application? Some sources suggest avoiding using them together due to their distinct lifecycles. We need to develop a responsive web application using ASP.NET WebApi and AngularJS. To achi ...

Transform the item that was dragged into something that can be dropped

Hey there, I'm currently utilizing jQuery UI for a simple operation involving draggable and droppable options within an ordered list (ol > Li). Within this setup, I have two specific items: category and subcategory. My goal is to allow users to d ...

The li elements in a horizontal menu all have equal spacing between them, filling the width of the ul

I designed a horizontal menu navigation system using HTML elements ul for the main menu container and li for menu list items. The layout is structured with display table for ul and table-cell for li. However, I encountered an issue where there are inconsis ...

My attempts at locating child elements using XPATH have been unsuccessful in finding an exact match

I have a specific requirement to input a string into the webdriver and then compare it with the label of a radio button. <input type="radio" onclick="Element.show('indicator_radio_term_190');render_selected_term('190','1', ...

Connect an AngularJS UI-Select to a UI-Grid filter

I am working on integrating AngularUI's ui-grid and ui-select together. This allows me to utilize ui-select functionality while filtering the ui-grid data. I have made some progress with a Plunker example that can be found here: http://plnkr.co/edit/ ...

Navigating through nested <ul> elements using Selenium and C#

Currently, I am attempting to loop through the <li> items within a <ul> object using Selenium with C#. As a newcomer to this, I am exploring ways to simplify the coding process for my testing project. Below is a snippet of the HTML code that I ...

What is preventing this code from successfully altering the opacity of an element based on its id?

I'm curious as to why the element's opacity is not temporarily reduced when the corresponding button is pressed. Any assistance would be greatly appreciated. function pause(miliseconds) { var currentTime = new Date().getTime(); while (cur ...

The div elements are not nested correctly as they should be

Essentially, I have a div element that contains a wrapper along with two other nested divs. One of these divs floats to the left while the other floats to the right. You can see how it appears here: Upon examining the code provided below, you'll not ...

Attempting to eliminate the parent container of a slide generated by the Slick Slider Plugin

I have developed a filter mechanism that hides specific classes within a slick slider based on the data-tag associated with the objects and the value of checkboxes. However, when these classes are hidden, they still occupy space because I should be hiding ...

Personalized CSS designs within the <option> element in an expanded <select> menu

Are there alternative methods for customizing an expanded select list using HTML or a jQuery plugin? I am interested in rendering each option in the list with multiple styles, similar to this example where the number is displayed in red: <select size=" ...

Retrieve the HTML value of the most recently deleted element in CKEDITOR

Having used CKEditor for several months, I've come across an issue related to deletion within the editor. My Question: How can I retrieve the HTML value of the last element deleted in CKEditor? Upon clicking the Delete button, I aim to identify the ...

precise placement of image inside pop-up

Having trouble positioning an image (an arrow) within a pop-up window. Attempted relative positioning to move the image precisely, but facing difficulties. Decided to go with absolute positioning instead, nesting a div within another div as shown below: ...