Maintain mouse attention through CSS

Currently, I am facing an issue with my login screen involving the mouseenter and mouseleave events. I have a gif image that disappears when the mouse hovers over it and reappears when the cursor moves to a different part of the page to allow users to enter their ID and password. However, there is a problem when I start typing my password and then move the mouse away, causing the caret focus to be lost.

Below are the relevant code snippets:

<div ID="contDefine" class="wipeForward" onmouseenter="fnToggleDefine1()" onmouseleave="fnToggleDefine2()">
<div ID="oDivDefine1" STYLE="position:absolute; width:454px; height:262px; background:#eff0f0 url('image/outlogin.gif') top repeat-x; ">   </div>
<div ID="oDivDefine2" STYLE="visibility:hidden; position:absolute; width:454px; height:262px; background: #eff0f0 url('image/inlogin.gif') top repeat-x; ">

function fnToggleDefine1() {
    if(agent.is_ie && !agent.is_ie10){
        contDefine.className='wipeForward';
        contDefine.filters[0].Apply();
        contDefine.filters[0].Play(duration=1);
    }
    oDivDefine2.style.visibility="visible"; 
    oDivDefine1.style.visibility="hidden";
}

function fnToggleDefine2() {
    if(agent.is_ie && !agent.is_ie10){
        contDefine.className='wipeReverse';
        contDefine.filters[0].Apply();
        contDefine.filters[0].Play(duration=1);
    }
    oDivDefine2.style.visibility="hidden"; 
    oDivDefine1.style.visibility="visible";
}

https://i.sstatic.net/0DntH.jpg

https://i.sstatic.net/OMJBK.jpg

Apologies for any language barrier. Thank you for your help.

Update: As my website only works in Internet Explorer, I attempted to modify my JS function.

function fnToggleDefine2() {
    if(agent.is_ie && !agent.is_ie10){
        contDefine.className='wipeReverse';
        contDefine.filters[0].Apply();
        contDefine.filters[0].Play(duration=1);
    }
    oDivDefine2.style.opaciy="0";
    oDivDefine2.style.zIndex="-999";
    oDivDefine1.style.visibility="visible";
}

Although I achieved the desired effect, it appears that opacity and zIndex are not functioning correctly in IE. Additionally, the caret focus keeps appearing even when the textbox is blocked by the image.

Please see the following image for reference:

https://i.sstatic.net/3yg1c.jpg

Note: For those who are having trouble understanding my question, please refer to the comment by Shuvro below.

Answer №1

Here is a suggested solution for your issue (if I understand correctly, you may need something like this): Demo

<ul class="demo-2 effect">
    <li>
       <h2 class="zero">This is an example!</h2>
       <p class="zero">Happy New Year</p>
    </li>
    <li><img class="top" src="http://s9.postimg.org/z8g84vbej/happy_new_year_2016_wallpapers.jpg" alt=""/></li>
</ul>

css

.demo-2 {
    position:relative;
    width:300px;
    height:200px;
    overflow:hidden;
    float:left;
    margin-right:20px;
    background-color:rgba(26,76,110,0.5)
}
.demo-2 p,.demo-2 h2 {
    color:#fff;
    padding:10px;
    left:-20px;
    top:20px;
    position:relative
}
.demo-2 p {
    font-family:'Lato';
    font-size:12px;
    line-height:18px;
    margin:0
}
.demo-2 h2 {
    font-size:20px;
    line-height:24px;
    margin:0;
    font-family:'Lato'
}
.effect img {width:200px; height:200px;
    position:absolute;
    left:0;
    bottom:0;
    cursor:pointer;
    margin:-12px 0;
    -webkit-transition:bottom .3s ease-in-out;
    -moz-transition:bottom .3s ease-in-out;
    -o-transition:bottom .3s ease-in-out;
    transition:bottom .3s ease-in-out
}
.effect img.top:hover {
    bottom:-96px;
    padding-top:100px
}
h2.zero,p.zero {
    margin:0;
    padding:0
}

Answer №2

If you want to achieve a specific effect using only CSS without the need for JavaScript, take a look at the code snippet below:

#box {
  width: 342;
  height: 160;
}

#box:hover > #imgover {
  opacity: 0;
  z-index: -999;
}

#imgover {
  width: 342;
  height: 160;
  position: absolute;
}

#input-field {
  margin: 20px 0 0 20px;
}
<div id="box">
  <img src="http://thumbs.dreamstime.com/t/demo-sign-d-letter-blocks-forming-isolated-white-background-36021240.jpg" id="imgover" />
  <input type="text" id="input-field" />
</div>

UPDATE

If you still prefer to use JavaScript, you can incorporate the focus() method to focus on the input field when the mouse enters the designated area. For more details on focus(), you can refer to this link. Keep in mind that this solution is tailored for a single input field. If you create a fiddle on jsfiddle, I can provide a more comprehensive JavaScript solution.

function fnToggleDefine1() {    
if(agent.is_ie && !agent.is_ie10){
    contDefine.className='wipeForward';
    contDefine.filters[0].Apply();
    contDefine.filters[0].Play(duration=1);
}
oDivDefine2.style.visibility="visible"; 
oDivDefine1.style.visibility="hidden";
var inputField = document.getElementById("YOUR-INPUT-FIELD-ID-TO-FOCUS-ON");
inputField.focus();
}

Setting opacity can be a more reliable approach compared to visibility, as it avoids potential browser compatibility issues that may lead to flickering.

function hideBox(box) {
  var container = document.getElementById("input-container");
  var image = document.getElementById("imgover");
  container.style.opacity = "1";
  image.style.opacity = "0";
  image.style.zIndex = "-999";
}

function showBox(box) {
  var container = document.getElementById("input-container");
  var image = document.getElementById("imgover");
  container.style.opacity = "0";
  image.style.opacity = "1";
  image.style.zIndex = "999";
}
#box {
  width: 342;
  height: 160;
}

#imgover {
  width: 342;
  height: 160;
  position: absolute;
}
<div id="box" onmouseenter="hideBox(this)" onmouseleave="showBox(this)">
  <img src="http://thumbs.dreamstime.com/t/demo-sign-d-letter-blocks-forming-isolated-white-background-36021240.jpg" id="imgover" />
  <div id="input-container">
    <input type="text" id="input-field" />
  </div>
</div>

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

What is the best way to implement a function on every item within a specific class?

I'm new to coding and I have a website that showcases job listings. I want to create a function that dynamically changes the logo of a company based on the first 50 characters of the company name mentioned. The current function only works for the firs ...

Can you explain the functionality of `module.exports = mongoose model` in a NodeJs environment

Coming from a front-end React background, I am familiar with statements like import and exports. However, as I delve into learning Backend (NodeJs) with mongoDB, I find myself curious about the mechanics of import and export in this new environment. I hav ...

Utilizing AngularJS and Bootstrap tooltips within a template

In my Rails-generated template, I am able to successfully add a Bootstrap tooltip in the application.html.erb file. However, when attempting to add a tooltip in a template partial loaded by AngularJS, it does not function as expected. Within the applicati ...

JavaScript Failing to Validate User Input in Form

I'm a beginner in JavaScript and I'm trying to validate a simple date of birth input, but for some reason, it seems that the JavaScript file is not working. No matter what I input, it always goes through, so I'm trying to figure out what&apo ...

What is the method to deactivate multiple links using jQuery?

Below is the HTML code: <a title="Login" data-href="/MyAccount/Access/Login" data-title="Admin" data-entity="n/a" id="loginLink" class="nav-button dialogLink"><b>Login</b></a> <a title="Register" data-href="/MyAccou ...

The problem of removing issue divs persists despite Jquery's efforts

Just yesterday, I successfully created a Commentbox using PHP, HTML, and ajax. The beauty of the ajax part is that it allows me to delete a comment without having to refresh the page. To achieve this, I assign a unique id to each comment (div) through the ...

"Encountering a problem with ThreeJs graphics rendering

I recently developed an application using ThreeJs, but I encountered a strange issue. After rendering the 3D graphics, the window appears blank. However, when I click on full screen or adjust the window size, the output becomes visible. Check out Screen s ...

Ways to align one child to the end without affecting any other elements

I'm attempting to position only div3 at the flex-end of .app. If I use this code: .app { display: flex; flex-direction: column; height: 100vh; justify-content: flex-end; } Div3 goes where I want it, but everything else also moves dow ...

"Are you familiar with delving into the intricacies of this

I've managed to implement a directive that changes a HTML class element when you scroll past a certain point on the page. However, the code is a bit of a mystery to me as I pieced it together from various online sources. I really want to understand ho ...

Guide to reducing the file size of your JavaScript code in Visual Studio Code

Does anyone have any recommendations for a Visual Studio Code plugin that can automatically minify JS files upon saving? I'm looking for a way to streamline the minification process. ...

Aurelia's numerous applications spread across various pages

Currently, I am in the process of finalizing the initial release of a large-scale website built using PHP (Phalcon), MySQL, and JQuery. The technology stack may be a bit outdated, but it was originally prototyped years ago and due to various circumstances, ...

ng-deep is causing changes in sibling components

Facing a challenge with Angular Material Design as I discovered the need to utilize ng-deep to customize the styling of an accordion. The issue is that when I use this method, it affects another accordion in a different section which is undesirable. Is th ...

Issue encountered when attempting to install React modules

Attempted to install sass-loader, as well as node-sass using both yarn and npm; however, encountered identical errors. Various methods were tried: yarn add <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="057664767628696a646160 ...

Can you explain the distinction between the terms "vite" and "vite preview"?

I recently created a project template with the help of vite. While looking through my package.json file, I noticed the following section; "scripts": { "dev": "vite", "build": "vue-tsc --noEmit &&a ...

Verification of Radiobox Groups in AngularJS

Could you please help me with validating a radiogroup using AngularJS, which is instantiated within an additional directive? The validation requirement is that the User must not be able to submit unless one of the radio buttons has been selected. This is ...

Incorporate Unicode characters into the structure of an HTML tag

I'm having an issue with the C# script below that is supposed to remove HTML tags from a description column in SSIS. I attempted to include the unicode value &#58 in the htmlTagPattern string, but it's not working as expected. Any help would ...

The afQuickField in Meteor is unable to locate the function when using the onfocus feature

I'm currently working on implementing a dynamic help feature that changes when the focus shifts using Meteor AutoForms. It's similar to the "Similar Questions" box that appears when you ask a question here. However, I'm encountering an issue ...

Get rid of empty spaces in gridstack js

My latest project involves using gridstack js In the image displayed, I have highlighted the excess white space (in blue) that needs to be removed. Take a look at this visual: https://i.sstatic.net/Qgt62.jpg Any suggestions on how to eliminate this ...

Is it possible for us to customize the angular material chip design to be in a rectangular shape

I recently implemented angular material chips as tags, but I was wondering if it's possible to customize the default circular design to a rectangle using CSS? ...

In Chrome, the $http GET request fails to send the JSESSIONID, but it functions properly on Firefox with AngularJS

Here is the code snippet I am working with: $http({ 'method': 'GET', 'url': 'http://www.example.com', 'withCredentials': true, headers: { 'Content-type': &apo ...