1

我正在尝试将属性放入类中并将其继承到每个 DIV ID。我的代码有什么问题?

var startItem1X = randomRange(50,100);
var startItem1Y = randomRange(50,100);
var startItem2X = randomRange(50,100);
var startItem2Y = randomRange(50,100);
var startItem3X = randomRange(50,100);
var startItem3Y = randomRange(50,100);
var startmyClassX = randomRange(50,100);
var startmyClassY = randomRange(50,100);
var $(".myClass").
    css(randomRange(50,100);); // push everything to the Class.

如何将这些属性添加到类中?

function runItem1() {
    /* Set a the starting position to be random by editing the css */
    $("#item1").css("left", startItem1X+"px");
    $("#item1").css("top", startItem1Y+"px");
    /* Cycle1 and Cycle2 variables allow infinite loop */ 
    (cycle1 = function() {
        var m = randomRange(50,100);
        var n = randomRange(75,150);
        item1.animate({left:'+='+n},2000);
        item1.animate({left:'+='+m, top:'+='+m}, 2000)
        item1.animate({left:'-='+m, top:'+='+m}, 2000)
        item1.animate({left:'-='+n},2000);
        item1.animate({top:'-='+n},2000,cycle1)
    })();

}
4

1 回答 1

0

如果我理解正确,您想更新样式表中编写的类。如果是这样,那么您需要使用“文档对象模型样式表”来完成。看看 -

http://www.javascriptkit.com/domref/stylesheet.shtml

http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html

于 2012-05-23T07:28:54.330 回答