Vanilla JavaScript version of jquery-hoverIntent

Overview

sv-hover-intent

sv-hover-intent is a JavaScript plugin for handling mouse hovers on a delay. It tracks when the mouse movement has slowed enough that it's likely the user intended to activate that element.

It's useful for things like dropdown menus, to avoid them popping out if you happen to move past them (for example, when closing the browser tab). See demo.html for an example.

This is essentially a vanilla JavaScript port of the excellent jQuery-hoverIntent plugin by Brian Cherne, though it has been rewritten from the ground up.

Usage

First add the script to your page like so:

<script src="sv-hover-intent.js"></script>

Or add it to your build process. Then in your site's JavaScript, call new SV.HoverIntent with an array or NodeList of the items you wish to apply it to, and an object containing the options. They are:

  • onEnter - (required) a callback to execute when hover is activated
  • onExit - (required) a callback to exexute when the mouse moves off the element
  • exitDelay - (optional) time in milliseconds to delay the exit function; useful for a dropdown menu if the user overshoots slightly
  • interval - (optional) polling interval for mouse tracking; only change this if you know what you're doing!
  • sensitivity - (optional) distance in pixels per interval, below which the hover will activate; only change this if you know what you're doing!

Here's a simple example, which adds and removes a "visible" class to a menu:

// get top-level items from a dropdown menu
var menuItems = document.querySelectorAll('.menu-item');

// set actions for mouse over and mouse leave
var hi = new SV.HoverIntent(menuItems, {
	// required parameters
	onEnter: function(targetItem) {
		targetItem.classList.add('visible');
	},
	onExit: function(targetItem) {
		targetItem.classList.remove('visible');
	},

	// default options
	exitDelay: 400,
	interval: 100,
	sensitivity: 7,
});
You might also like...

Portuguese version of the Cassandra driver javascript node.js workshop

Versão em Português do workshop Cassandra driver javascript node.js Olá e bem-vindo! Este é o repositório complementar para a apresentação prática dos

Mar 17, 2022

This is the improved version of Simon game using JavaScript and Html.

simon-game simonoo.mp4 What is this Game This is the improved version of Simon game using JavaScript and Html. you have 10 levels to complete until yo

Oct 23, 2022

A simple To-do app project made using JavaScript ES6 and Webpack - Microverse. You can add, remove, check tasks, and remove all the tasks that were done at the same time. Feel free to see the live version, if you like it please give it a star!

To Do List a to do list javascript app buit using webpack and es6. Built With HTML CSS JavaScript Wepack Live Demo (if available) Live Demo Link Getti

Dec 17, 2022

Odoo Javascript Framework Training (public version)

Introduction to JS framework Introduction For this training, we will put ourselves in the shoes of the IT staff for the fictional Awesome T-Shirt comp

Dec 16, 2022

JQuery charCounter - jQuery Character Counter Plugin

JQuery charCounter - jQuery Character Counter Plugin

jQuery Character Counter A jQuery based character counter for input and textarea HTML tags. What is this? This simple plugin allows you to add a c

Aug 10, 2022

Jquery-actualizer - jQuery ajax actualizer

jQuery AJAX Actualizer Include jQuery & this plugin into your HTML file and use this js code: $('#target').actualizer('a'); On click at any A element,

Jul 28, 2020

jQuery quick notification plugin. jQuery плагин быстрых уведомлений

Note: English translation by Google Translate Notific About Description: this is a jQuery plugin that helps you display notifications on your site. Li

Nov 7, 2021

jquery-input-mask-phone-number.js - A simple, easy jquery format phone number mask library

jquery-input-mask-phone-number.js - A simple, easy jquery format phone number mask  library

jquery-input-mask-phone-number A jQuery Plugin to make masks on input field to US phone format. Quick start 1. Add latest jQuery and jquery-input-mask

Aug 25, 2022
Comments
  • Doesn't work when used on nested items

    Doesn't work when used on nested items

    When I hover a nested item that also has the over event, the onExit event is triggered on the parent. This feature works well on the original jQuery plugin, it allows me to build menus with nested submenus.

    opened by ivansimplistic 0
Owner
Scott
Scott
Text annotation solution for websites. TypeScript and vanilla JavaScript version.

Simple Text Annotations Use this small library when you need to add annotations to your website. Features show up / hide annotation on a element click

Jacek Jarczok 1 May 9, 2021
The Remix version of the fakebooks app demonstrated on https://remix.run. Check out the CRA version: https://github.com/kentcdodds/fakebooks-cra

Remix Fakebooks App This is a (very) simple implementation of the fakebooks mock app demonstrated on remix.run. There is no database, but there is an

Kent C. Dodds 61 Dec 22, 2022
This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Eduardo Dantas 7 Jul 19, 2022
Plain JavaScript version of jQuery's slideToggle(), slideDown(), & slideUp(), but does not use display: none.

dom-slider It works like jQuery's slideToggle(), slideDown(), & slideUp(), but does not use display: none. Uses CSS3 transitions and element.scrollHei

Brenton Cozby 56 Dec 27, 2022
Wallpaper Engine but online-version. (HTML, CSS, JS with jQuery, PHP)

Project Preview - Web Wallpaper Engine About Wallpaper Engine but online-version. View animated wallpapers directly in your browser. Case: Create web-

Dmitry Britov 11 Dec 30, 2022
Create your own password generator using jQuery, Vanilla JS, and SASS.

Password Generator Create your own password generator using jQuery, Vanilla JS, and SASS. I have been working with JS for my last few projects so I th

The Dev Drawer 1 Jul 12, 2021
Navigation-Menu-Javascript - A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked.

Navigation-Menu-Javascript A simple Navbar navigation using vanilla javascript, to change links to the active link when clicked. Desktop view Mobile v

Ellis 2 Feb 16, 2021
MenuSlider-Javascript - How to create a menu slider with vanilla javascript

MenuSlider-Javascript How to create a menu slider with vanilla javascript Instal

Tarokh Mohammadi 1 Feb 8, 2022
Leader Board is a simple project based on JavaScript programing language. The purpose of this project is to work with APIs and ASYNC & AWAIT methods. I have used vanilla JavaScript with web pack to implement this project

Leader Board - JavaScript Project Table of contents Overview The challenge Screenshot Links Project Setup commands My process Built with What I learne

Mahdi Rezaei 7 Oct 21, 2022
It maintains my version of js notes which I learned from the famous Namaste Javascript Youtube Series by Akshay Saini.

Welcome to Namaste Javascript Notes ?? ❓ what it is This repo maintains my version of javascript notes which I learned from the famous Namaste Javascr

Alok Raj 682 Jan 4, 2023