留言板

custom theme-javascript problem

biswajit sarkar,修改在12 年前。

custom theme-javascript problem

Regular Member 帖子: 166 加入日期: 11-10-17 最近的帖子
i am creating a custom theme.......in my theme there would be dyanamic background images....

when ever page refresh the background image change randomly.
here's my code of java script----->
---------------------------------------------------------------------------------------------
<!DOCTYPE html>

#parse ($init)

<html class="#language("lang.dir")" dir="#language("lang.dir")" lang="$w3c_language_id">

<head>
<title>$the_title - $company_name</title>

$theme.include($top_head_include)
<script type="text/javascript">
function bgLoad() {
var bimages = ["../images/layout/bg_html1.jpg", "../images/layout/bg_html2.jpg", "../images/layout/bg_html3.jpg"];
var rand=Math.floor(Math.random()*3);
newImage = 'url('+bimages[rand]+')';
document.body.style.background = newImage;
document.body.style.backgroundSize = '100%';
}

</script>
</head>

<body class="$css_class" onload="bgLoad()">

------------------------------------------------------------------------------

but whenever I refresh the page it gives an error and images not load.........


the error


11:01:05,175 INFO [PortalImpl:3829] Current URL /images/layout/bg_html2.jpg generates exception: null

i think my javascript is ok and images path also ok.......

why I dont get the images...

please help....
Prasanna Raj,修改在12 年前。

RE: custom theme-javascript problem

Junior Member 帖子: 68 加入日期: 12-1-30 最近的帖子
biswajit sarkar:
i am creating a custom theme.......in my theme there would be dyanamic background images....

when ever page refresh the background image change randomly.
here's my code of java script----->
---------------------------------------------------------------------------------------------
<!DOCTYPE html>

#parse ($init)

<html class="#language("lang.dir")" dir="#language("lang.dir")" lang="$w3c_language_id">

<head>
<title>$the_title - $company_name</title>

$theme.include($top_head_include)
<script type="text/javascript">
function bgLoad() {
var bimages = ["../images/layout/bg_html1.jpg", "../images/layout/bg_html2.jpg", "../images/layout/bg_html3.jpg"];
var rand=Math.floor(Math.random()*3);
newImage = 'url('+bimages[rand]+')';
document.body.style.background = newImage;
document.body.style.backgroundSize = '100%';
}

</script>
</head>

<body class="$css_class" onload="bgLoad()">

------------------------------------------------------------------------------

but whenever I refresh the page it gives an error and images not load.........


the error


11:01:05,175 INFO [PortalImpl:3829] Current URL /images/layout/bg_html2.jpg generates exception: null

i think my javascript is ok and images path also ok.......

why I dont get the images...

please help....


Liferay recognizes your custom java scripts written inside main.js or you can place your custom script inside the $javascript_folder/js and import it in your portal_normal.vm.
thumbnail
Akris K,修改在12 年前。

RE: custom theme-javascript problem

New Member 帖子: 9 加入日期: 11-4-14 最近的帖子
Hi ,

try using the variable $images_folder to refer to the path of the theme images folder.

var bimages = ["$images_folder/layout/bg_html1.jpg", "$images_folder/layout/bg_html2.jpg", "$images_folder/layout/bg_html3.jpg"];

HTH
Anup
gauri ahire,修改在11 年前。

RE: custom theme-javascript problem

New Member 发布: 1 加入日期: 12-4-21 最近的帖子
i am trying to do the same thing....the function bgload() does not work!!!

plz help
biswajit sarkar,修改在11 年前。

RE: custom theme-javascript problem

Regular Member 帖子: 166 加入日期: 11-10-17 最近的帖子
gauri ahire:
i am trying to do the same thing....the function bgload() does not work!!!

plz help



sorry 4 late...
that function work for me...
can you share your code here??