Setting a background images with jQuery

22 views
Skip to first unread message

mostwanted

unread,
Feb 20, 2020, 12:36:43 PM2/20/20
to web2py-users
I cant seem to be able set a background image with jQuery using css in web2py, I have been trying to create a background slide but all i am getting is white canvas!
I dont know why this is happening!

<script>
     
var images=new Array('images/fairytale.jpg','images/gamaila.jpg','images/gathuli.png');
var nextimage=0;
doSlideshow
();

function doSlideshow(){
   
if(nextimage>=images.length){nextimage=0;}
    $
('.background')
   
.css('background-image','url("'+images[nextimage++]+'")')
   
.fadeIn(500,function(){
        setTimeout
(doSlideshow,1000);
   
});
}
</script>


Even a simple script such as this one cant do it, i'm suspecting there is something wrong with way i'm calling the images, the path i'm giving, please help
<script>
$
(document).ready(function(){
$
(".background2").css("background", "url(' ../images/background.jpg ')");
});
</script>

Regards;

Mostwanted

Paco Bernal

unread,
Feb 20, 2020, 4:31:47 PM2/20/20
to web2py-users
Maybe you can try with https://domain/static/images/background1.jpg in the array because you need to get the picture from the server and the URL you are using does not point to any picture in front side
I think...

Paco Bernal

unread,
Feb 20, 2020, 4:51:05 PM2/20/20
to web2py-users
Think that this will work for sure, I am using something similar

<script>
$
(document).ready(function(){
$
(".background2").css("background", "url('{{=URL('static', 'images/background.jpg)}}')");
});
</script>

Well, the code I use is

('body').css({'background-image':'url({{=URL('static','images/%s' % pic)}})'});

for showing a random picture in the login screen
Regards
Reply all
Reply to author
Forward
0 new messages