Hovering over a CSS3 gradient causes it to flicker

Playing around with a CSS3 Gradient and attempting to move it on mouseover. The CSS gradient appears on :hover, but there is some flickering happening as shown in this jsFiddle link.

For your information, I have tested this on Chrome v30 / Firefox v24 / Safari v5.1.

While both parts work individually, I am experiencing the flickering effect when combined.

nav li {
    width: 90px;
    padding-right: 15px;
    padding-left: 15px;
    height: 30px;
    border: 1px solid #000;
    float: left;
    list-style-type: none;

    background-position: -200px -200px;
    -webkit-transition: background 1s ease-out;
    -moz-transition: background 1s ease-out;
    -o-transition: background 1s ease-out;
    transition: background 1s ease-out;
}

nav li:hover {
    background-position: 200px 0;
    background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIw...

I attempted to control the animation using animation-iteration-count, which only seemed to work with animations and @keyframes. It has been noted on various sites that @keyframes do not yet fully support CSS Gradient animation.

Answer №1

The flickering effect is caused by the discrepancy between your element's height (30px) and the background offsets you've specified (-200px -> 0px).

In essence, as it scrolls past the view six times within a one-second transition (because 30 fits into 200 six times), this creates the flickering effect. To make this more evident, try extending the transition time to 5 seconds; this will highlight what is happening more clearly. (Remember to reset the transition time after testing.)

If you adjust the initial background-position to -30px instead of -200px, it will only scroll into view once, eliminating the flicker.

I hope this explanation helps.

Answer №2

One issue lies in the background-repeat property. To prevent the background from being displayed before hovering, make sure to set it to no-repeat.

background-repeat: no-repeat;

Example Link

Answer №3

Like others have mentioned, the issue lies with the background-repeat property and your overly large background position.

For an updated version of what you were aiming for, check out this link to a revised Fiddle.

I've eliminated unnecessary CSS rules since all major browsers now support gradients and transitions without prefixes. It's worth noting that -ms-transition and -ms-linear-gradient never actually existed, as IE didn't rush into adopting them. Did you know there are at least THREE different ways to define gradients in Chrome alone?

In addition to streamlining the code, I've relocated the background definition to the element's styles (instead of its hover styles) to ensure a smooth transition effect when hovering in and out. By setting background-repeat:repeat-x for horizontal repeating only, and adjusting the background-position, the gradient stays positioned perfectly during the transition stages.

This should provide a seamless user experience - hope it resolves your issue!

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

The auto-fill feature provided by Google on my form

On my website, I have a form that redirects textbox input to www.google.com/search?q=.... Is there a way to incorporate the autocomplete / autofill features provided by Google when searching on google.com? I've noticed that Firefox uses Google's ...

Intersecting table columns with a different data table

My task is to create a table with a column that contains another table, where I want the colors of each alternating row to be different. Please refer to the image below (ignore the "CharacterAgain" column). Below is an example of AngularJS code for the ta ...

Discover the way to create an HTML button with a mesmerizing transparent effect

For my website creation using Dreamweaver, I came up with the idea of utilizing Photoshop to design backgrounds. The reasoning behind this choice was that if I needed to modify button names at any point, I could simply edit the code and make the necessary ...

leveraging jquery for delaying, subsequently fading out, and ultimately removing

I am currently working on a website that has a dialog feature which I am trying to make functional by following these steps: The dialog is created using .append() method, then it is set to wait for 5 seconds before fading out and being removed. Despite my ...

Choosing limits or beginning & ending positions of a string in angular js

I'm facing an issue with extracting a substring from a string on my webpage that was developed using MEAN. I am currently selecting the substring by dragging the mouse (ng-mouseup). However, I need to determine the start and end positions or length of ...

Is there a way to set the value of formValidity as the content of an HTML5 element that is both bound and updated by ngModel?

I need to transfer the boolean value retrieved from myForm.valid to my Angular 2 component. This involves retrieving it in the component using two-way binding since it is a template-driven form. The current code provided does not seem to be working for t ...

Identifying shifts in offsetTop

In my design, I have a page where scroll bars are not allowed, meaning all content must be visible at once. The image below shows the basic layout of the screen to give you an idea. The layout consists of two blocks - Block 1 and Block 2. Block 1 is expan ...

Transforming a numerical function into an HTML span tag: A quick guide

Looking for assistance with updating the last line. The goal is to display the current month, obtained from the getMonthText variable, within the <h1><span id="month_year">&nbsp;</span></h1> Starting code. The issue arises to ...

Navigating high quality images

I am currently working on the development of a basic web app for iPhone and Android using phonegap. I am facing some challenges with providing high-resolution images for newer Android devices. My initial thought was to use the same images created for the i ...

Struggling to make a variable pass in an Ajax post script

Having trouble passing the "filename" variable from main.php to save_sign.php. Can anyone provide assistance? main.php <? $filename="222222"; ?> <script> $(document).ready(function() { $('#signArea').signat ...

Responsive Design of Iframe Not Adjusting Properly

My website features an embedded Google map in an iframe: <iframe src="https://www.google.com/maps/d/u/0/embed?mid=EXAMPLE" style="top:0px; position:fixed; float:left; width:35%; height:400px;"></iframe> Adjacent to the map, ...

Updating disabled date picker appearance in Angular Material Design

I am currently developing a website using Angular Material. One of the components I am working with is a date picker. The issue I am facing is that the date picker has the popup functionality enabled, but the input itself is disabled, causing a dotted line ...

unable to display options in my select element | Angular and Ionic

I need help displaying my category options: <div class="row" style="margin-bottom:15px;padding:0;padding-top:0px;padding-bottom:0px;"> <div class="col col-white" style="height:45px;background-color:#EDEEF1;padding-top:6px"> <div class=" ...

How can you insert content or advertisements into the HTML generated by a PHP server?

I'm currently utilizing Laravel and Vue.js in my project. Although it may seem like a simple query, I want to ensure that everything is working properly before moving forward. This involves... Utilizing a WYSIWYG editor to save content into an HTM ...

Build interactive web pages using Python scripts

By utilizing the Python scripts provided below, you can generate an HTML file with pre-set global variables (a, b, c, d). However, there might be instances when certain variables are not set globally, resulting in errors like "global 'a' is not d ...

Achieving a layered effect with elements overlapping onto another div

Looking for a way to create a design where the text in id="text-field" overlaps with id="image-field". Need some guidance on how to achieve this effect. Any help is appreciated. <!DOCTYPE html> <html> <body> <div class=" ...

Transforming the table into a list by categorizing every 3 rows together

SharePoint tends to use nested tables excessively, causing issues when trying to implement a jQuery carousel on them. To resolve this, I discovered a piece of jQuery code that can convert a table into a list: var list = $("<ul/>"); $('#tab1&apo ...

Sketch a bounding box around an image displayed within a modal

I am a JavaScript beginner and currently working on a small code project that involves displaying an image inside a modal. I am attempting to draw a bounding box over the image. Below is the code snippet I've used to try drawing the bounding box: HT ...

What are the best methods for preserving paint color when changing wheel styles, and vice versa?

I posted this query about a year ago, but I did not have a fiddle prepared at that time and my question was not as well articulated as it could have been. Despite that, many people came forward to offer their help, and I am truly grateful for that. This ti ...

Troubleshooting my HTML5 local storage issues for optimal functionality

I've been working on using HTML5's localstorage to save two variables and load them upon page refresh, but I seem to be encountering some issues when trying to load the saved items: Variables in question: var cookies = 0; var cursors = 0; Savi ...