ورود

View Full Version : سوال: لود تصادفی Css



manoto1371
پنج شنبه 20 فروردین 1394, 15:12 عصر
سلام
من از کد جاوا اسکریپت زیر برای لود شدن تصادفی Css استفاده میکنم اما این کار انجام نمیشه؟
کسی میتونه کمک کنه ؟



<script>
var link = [];
link[0] = "css/bootstrap.css";
link[1] = "css/bootstrap2.css";
$(function() {
var style = link[Math.floor(Math.random() * link.length )];
alert("sddsd");
if (document.createStyleSheet){
document.createStyleSheet(style);
}else{
if(style == 0){

$('<link />',{
rel :'stylesheet',
type:'text/css',
href: style
}).appendTo('head');

$('<link />',{
rel :'stylesheet',
type:'text/css',
href: 'css/flat-ui.min.css',
}).appendTo('head');

}else{

$('<link />',{
rel :'stylesheet',
type:'text/css',
href: style
}).appendTo('head');

}
}
});
</script>

mehbod.rayaneh
پنج شنبه 20 فروردین 1394, 15:38 عصر
درود


<html>
<head>
<title>استایل تصادفی!</title>
<script>
var RANDOM_CSS = {
cssfiles : ['style1.css','style2.css','style3.css','style4.css ','style5.css','style6.css'],
pathtocss : 'css/',
getrandomcss : function() { return this.cssfiles[Math.floor(Math.random()*this.cssfiles.length)]; },
getlinktag : function() { return '<link rel="stylesheet" type="text/css" href="'+this.pathtocss+this.getrandomcss()+'" />'; },
printlinktag : function() { document.write(this.getlinktag()); }
};
RANDOM_CSS.printlinktag();
</script>
</head>
<body>
<h1>هدینگ مثلا</h1>
<p>پاراگراف مثلا</p>
</body>
</html>

استایل 1-6 را در فولدر css قرار بدید دیگه! رندوم لود میکنه!
پیروز باشید