Searching for a method to modify the font of individual letters when hovering over them. The goal is for the letters to revert back to their original font after a second hover (not on the first hover-off).
Any assistance would be greatly valued!
Searching for a method to modify the font of individual letters when hovering over them. The goal is for the letters to revert back to their original font after a second hover (not on the first hover-off).
Any assistance would be greatly valued!
Find more information about classList here
Check browser support for classList
var elLi = document.querySelectorAll('li');
for (var i = 0; i < elLi.length; i++){
elLi[i].onmouseover = function(){
this.classList.toggle("times");
}
}
body {
font-family: 'Arial';
}
li {
margin: 10px 0;
}
.times {
font-family: 'Times';
}
<ul>
<li>Text 1</li>
<li>Text 2</li>
</ul>
var elLi = document.querySelectorAll('li');
for (var i = 0; i < elLi.length; i++){
elLi[i].onmouseover = function(){
if (hasClass(this, 'times')) {
this.className = "";
// Remove class
} else {
// Add class
this.className = "times";
}
}
}
function hasClass( target, className ) {
return new RegExp('(\\s|^)' + className + '(\\s|$)').test(target.className);
}
body {
font-family: 'Arial';
}
li {
margin: 10px 0;
}
.times {
font-family: 'Times';
}
<ul>
<li>Text 1</li>
<li>Text 2</li>
</ul>
Check out this easy jQuery example:
let hoverCounter = 0;
$('.post-text').hover(function(){
//hover in
hoverCounter++;
//console.log(hoveredCounter);
if(hoverCounter == 1){
$(this).addClass('new-font');//or $(this).css('font-family', 'Arial');
} else if(hoverCounter == 2) {
$(this).removeClass('new-font');//or $(this).css('font-family', 'Verdana');
}
}, function(){
//hover out
})
.old-font{
font-family: "Arial";
}
.old-font.new-font{ /* using 2 classnames so the rule will have bigger priority*/
font-family: "Verdana"
}
If you want to make each letter changeable, you'll need a separate <span>
for each one. You can automate this process using https://github.com/davatron5000/Lettering.js.
I have been researching how to create a circular progress bar using canvas, and I came across this code. After making some modifications to the code snippets that I found online, I encountered an issue - I can't seem to reload the circular path once i ...
As a newcomer to HTML, CSS, and Bootstrap, I encountered an issue with overlapping divs when resizing the screen to be smaller. The problem arose when using container-fluid as a section and implementing a customized div for the section header. Despite atte ...
Can anyone help me out here? I have a div containing 4 elements that are currently stacked on top of each other. I want them to be aligned horizontally instead. The div's ID is #ninesixty. Thank you in advance! HTML <header> <div id="ni ...
I am looking to achieve a similar effect using JavaScript instead of just pure CSS like the example provided. I'd prefer not to use SCSS either, just sticking to CSS would be great. Please check out this CodePen for reference. .picture-container ...
HTML CODE <div id="scrollidout" style="overflow: auto; overflow-y: hidden; "> <div id="scrollidin" style="padding-top: 1px; height: 20px; width: 1000px"> </div> </div> <div class="resultcontent" style="overflow ...
Below is an array with objects that need to be sorted: [ { "Books": [], "_id": "5dea9a11a8e1bf301c462ce4", "FileName": "AAAAA", "Order": 99999 }, { "_id": "5dea9864a8e1bf301c462cdb", "Books": [], "FileName": "some1", ...
After learning that each element in the dropdown must be given by the Option tag when using Select, I created an array of values for the dropdown: a = ['hai','hello','what'] To optimize my code, I wrote it in the following ...
When working with native JS, I am familiar with using AJAX to display the output from PHP/mySql that is not Json Encoded in the element "some_id" like this: <script> function addItem(value) { xmlhttp = new XMLHttpRequest(); xmlhttp.onrea ...
Issue with my express application: Even after reaching the error middleware, the second middleware function is still being executed after res.json. As per the documentation: The response object (res) methods mentioned below can send a response to the cl ...
I'm a beginner with Ionic and I'm looking to customize the items on the header bar. It appears that the header bar is created by the framework within the ion-nav-bar element. <ion-nav-bar class="bar-positive"> <ion-nav-back-button> ...
After conducting research online, I found myself unable to resolve my issue due to my lack of proficiency in English. I apologize for any confusion caused and would like to revisit the topic. The problem lies with my navbar toggle that is not functioning ...
Currently utilizing Bootstrap 3 and AngularJs for this project. Implementing the following markup for the input field with type 'search': <input type="search" class="form-control" id='roomSearch' placeholder="Search" ng-model=&apo ...
I am struggling to make my current CSS and HTML menu fully responsive and mobile-friendly. I have researched solutions from other sources but have been unable to implement them successfully. I am seeking help in modifying my menu so that it adjusts to smal ...
let itemList = ['X', 'Y', 'Z']; Even though the array is cleared, the user interface does not reflect the change. itemList = []; This method solves the issue. But why? itemList.length = 0; ...
As a beginner in web design and utilizing bootstrap, I am creating a website with two columns of size 6 each within a row. || Col-1 || Col-1 || [Web View] ||||||||||| || Col-1 || ||||||||||| || Col-2 || ||||||||||| [Mobile View] However, I would like th ...
I am currently working on my JavaScript skills and would like to implement a fun project involving 10 colorful circles. While I can easily create these circles using HTML and CSS, I require assistance with the interactive functionality using JavaScript. ...
Attempting to lock the screen orientation in portrait mode for mobile and iPad devices using a CSS snippet found on css-tricks.com. @media screen and (min-width: 320px) and (max-width: 767px) and (orientation: landscape) { html { transform: rotate ...
In a JavaScript code in my JS file, I have the following function: var obj, mtl; init(); animate(); var MYLIBRARY = MYLIBRARY || (function () { var _args = {}; // private return { init: function (Args) { _args = Args; ...
Currently, I am working on a project using Angular and firebase. My goal is to develop a function that can take two arguments - a string and an object, then return an Observable containing filtered data based on the key-value pairs in the object for a spe ...
I am facing an issue with my HTML & CSS automatic horizontal slideshow. Everything works fine, except for when the last image finishes sliding and the slideshow loops back to the first image, there is a sudden jump in the appearance of the first image. How ...