Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8526595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:18:59+00:00 2026-06-11T08:18:59+00:00

I am using css3 animations to move items from one side of the screen

  • 0

I am using css3 animations to move items from one side of the screen to the other. I want to make sure this effect works regardless of screen resolution. In order to do this, I use document.styleSheets in order to get access to the css file with all of the animation keyframes and change their final values.

Here is the js code I am using:

var stylesheet = document.styleSheets[1];

var rules = stylesheet.rules;
var keyframes;
var keyframe;

for (var i = 0; i < rules.length; i++){
    keyframes = rules.item(i);

    var keyframeRules = keyframes.cssRules;
    var j = keyframeRules.length;
    var index = i+1;

    while (j--) {
        keyframe = keyframeRules.item(j);
        if (keyframe.keyText === "100%") {
            if(keyframe.style.left != ''){
                keyframe.style.left = $(document).width() + $('#cloud'+ index).width() + 'px';
            }
        }
    }

    $('#cloud'+ index).addClass('animating');
}

The css file I am using contains:

@-moz-keyframes cloud1 {
0%{ left: -400px; }
100%{ left: 0; }
}

@-webkit-keyframes cloud1 {
0%{ left: -400px; }
100%{ left: 0; }
}

I have quite a few pairs of keyframes in there.

My problem is document.styleSheets returns an empty css file if I console.log it and inspect in firebug. As a result, rules.length is null. Webkit based browsers work without any issues.

Am I missing something obvious here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:19:01+00:00Added an answer on June 11, 2026 at 8:19 am

    Different browsers use different names to refer to those rules.

    Here’s how I handle this problem in my code :

    var cssRules = stylesheet.rules; // chrome, IE
    if (!cssRules) cssRules = stylesheet.cssRules; // firefox (and maybe Chrome too in recent versions)
    

    You could do it as :

    var cssRules = stylesheet.rules || stylesheet.cssRules; 
    

    But I prefer the first version as it’s clearer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make this button using CSS3: But my button looks like
I'm trying to create a fade out / fade in effect with CSS3 animations.
Could we move background image instead of moving div by using css3 animation? For
Stick with me on this one. I'm trying to mimick CSS3 transitions and (as
I'm trying to make some icons jump on hover using CSS3 and Jquery. The
I have this navigation bar with a rollover using css3 animation. It functions great
I'm using CSS3 border-radius to create circular buttons on this site: http://hexpreview.com/ However, due
I am trying to make a dropdown effect for one of my background images.
Sencha Animator is using CSS3 animations exclusively. RaphaelJS is using SVG animations. I wonder
I'm building a WebApp for iPad using Knockout.js and CSS3 Animations. The transition between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.