javascript - Simple jQuery Tooltip (position distorted on iPad) -


i've used simple jquery ui tooltip on form-fields of webpage(viz responsive), working on desktop on every browser, on ipad distorted when tap on form-fields keypad swipe-up. header section of webpage gets fixed on scroll. i've used below code custom jquery tooltip.

$(function () {     $('.form-control').tooltip({       disabled: true,       position: {       my: "left top",       at: "left top-50",       using: function( position, feedback ) {         $( ).css( position );         $( "<div>" )         .addclass( "arrow" )         .addclass( feedback.vertical )         .addclass( feedback.horizontal )         .appendto( );       }       }     }).on("focusin", function () {          $(this)             .tooltip("enable")             .tooltip("open");      }).on("focusout", function () {         $(this)             .tooltip("close")             .tooltip("disable");     });  }); 

i've written code re-initialize tooltip focused field calling focusin trigger manually when document size changed. working expected on desktop browsers on ipad tooltip being re-initialized @ same place again viz incorrect.

var tooltipel; $('#inputsuccess, #inputwarning').tooltip({   open: function (event, ui) {    tooltipel = event.target; } }); function checkdocumentheight(callback){ var lastheight = document.body.clientheight, newheight, timer; (function run(){   newheight = document.body.clientheight;    if( lastheight != newheight )     callback();   lastheight = newheight;   timer = settimeout(run, 100); })(); } function dosomthing(){   console.log('document resized');   settimeout(function() { if ($(tooltipel).is(':focus')) {   $(tooltipel).trigger('focusout').trigger('focusin');     }  }, 500); } checkdocumentheight(dosomthing); 

please me find out solution this.

you need reinitialize active tooltip after completion of event cause change in content (actually height) of document affecting tooltip position.

first keep reference of element tooltip active listening events adding following codes in tooltip initialization (keep existing code is. add these additional statements).

var tooltipel = undefined;  $(function () {      $('.form-control').tooltip({        open: function (event, ui) {         tooltipel = event.target;       }      }).on("focusin", function () {           tooltipel = undefined;      }).on("focusout", function () {          tooltipel = undefined;      }).on("mouseleave", function () {          tooltipel = undefined;      });  }); 

please note, displaying tooltip on focusin event well. so, need release variable if not want tooltip pop-upped if focus has changed/left.

and create function resetting tooltip below.

function resettooltip() {   if (tooltipel) {     $(tooltipel).trigger('focusout').trigger('focusin');   }; } 

call function in events causing change in document height. example if content coming ajax request. can call resttooltip function listing gloab ajax events. see example below.

$( document ).ajaxcomplete(function() {   resettooltip(); }); 

i hope you. ask me if need further clarification.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -