Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  51] [ 4]  / answers: 1 / hits: 26721  / 12 Years ago, thu, february 21, 2013, 12:00:00

Is it possible to use JS to automatically and continuously change a particular CSS property?



I want to create glowing border whose glow continuously brightens and dampens (using 3 properties to achieve this effect - border, box shadow, inset box shadow). How can I do so?



Please note that I am not talking about using hover or active states.
Also I want it to work in all browsers, if possible.


More From » css

 Answers
24

If this has to be a JS solution, the following will work for you.



CSS:



#myGlower {
background-color: #ccc;
border: 1px solid transparent;
-webkit-transition: border 0.1s linear, box-shadow 0.1s linear;
-moz-transition: border 0.1s linear, box-shadow 0.1s linear;
transition: border 0.1s linear, box-shadow 0.1s linear;
}

#myGlower.active {
border-color: blue;
-webkit-box-shadow: 0 0 5px blue;
-moz-box-shadow: 0 0 5px blue;
box-shadow: 0 0 5px blue;
}


And then using jQuery:



$(function() {  
var glower = $('#myGlower');
window.setInterval(function() {
glower.toggleClass('active');
}, 1000);
});


You can see a jsFiddle here. While this is achievable using JS, you could also use CSS3 animations.



Also, you won't be able to get it to work in all browsers, as not all of them support the CSS properties that you mentioned (transitions, box shadow, etc.).


[#80075] Wednesday, February 20, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cadendericki

Total Points: 482
Total Questions: 109
Total Answers: 103

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
cadendericki questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Wed, Jul 8, 20, 00:00, 4 Years ago
Thu, May 14, 20, 00:00, 4 Years ago
;