How to have a div show up when hovering over elements but not appear over the mouse pointer?

xilex

I have multiple elements in a page where hovering over an element will show another div. Example code is in the jsfiddle. The problem is when the cursor goes on the right, this div will cover up the content beneath the cursor. What are ways to make it so the div is out of the way? In this case, the div should be in the lower half or the left side.

Do I test for cursor position and redefine the position of the hidden div based on where the cursor is? Or is there something built-in that can do it? Thanks.

<div class="container">
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>
  <div class="box"></div><div class="box"></div>

  <div class="flyout hidden"></div>
</div>

https://jsfiddle.net/p89ag5zu/2/

Brandon Gano

You can use JavaScript to track the mouse movement and apply positioning classes on the flyout. This is pretty inefficient, but it works:

https://jsfiddle.net/p89ag5zu/3/

var $container = $('.container');
// This would be much faster if you throttle calls to the handler.
// Google "JavaScript event throttling" for examples.
$container.on('mousemove', function (e) {
  // This would be much faster if you store the container offset values.
  // Note that you might need to re-calculate when the screen size changes.
  if ((e.clientX - $container.offset().left) < $container.width() / 2) {
    $flyout.removeClass('left');
    $flyout.addClass('right');
  }
  else {
    $flyout.removeClass('right');
    $flyout.addClass('left');
  }
  if ((e.clientY - $container.offset().top) < $container.height() / 2) {
    $flyout.removeClass('top');
    $flyout.addClass('bottom');
  }
  else {
    $flyout.removeClass('bottom');
    $flyout.addClass('top');
  }
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to show font on hovering the mouse over image

How to scroll up a div when hovering over another element

How to make an image in a <div> appear when you mouse over it?

How to make a message show up when mouse over icon

In Labview how can I change the mouse pointer when hovering over one of my boolean controls?

Multiple images depending on mouse location when hovering over div

Tkinter mouse pointer not working for hovering over button

Show div only when the mouse hovers over it

When hovering over <ul> I want another <ul> to show up

Hovering makes elements appear over each other

Show text over a image when hovering over it

How to make labels appear when hovering over a point in multiple axis?

How to make a tolltip appear only when hovering over text?

How to make the border appear when hovering over a button in Kivy

How to show label when mouse over bar

How to display a div when hovering over another div

(How to) When hovering over a logo, transforms up and text appears underneath?

how to show a content after and a tooltip when hovering over it?

How to show the dropdown when hovering over the dropdown list

How to stop the elements from growing when hovering over an element?

How to change the style of other elements when hovering over one of them?

How to change a plot when hovering over elements in Shiny?

How to trigger div visibility when hovering over list item in CSS?

D3.js Chord diagram - Have text appear/disappear when hovering over an arc

Show text in a box when hovering over word

Show info when hovering over a tag

How to make tooltips show up when mouse hovers over data point

How can I make a element show when hovering over another element, and hide it if not. And make it take up space the entire time

Resize the elements when mouse over