hi, just wondering if there was a way of dynamically setting a background image for a div depending on the page you are on. there's no need to create a seperate template as the structure's exactly the same.
i have done this on a few project... basically, use a media picker on the node.. for background image... and in your template, insert a macro that renders the div according... or you could use some inline xslt too... :)
on this site... http://test.mtturl.com i use some jquery to scale the backgound image...
//Resize image on ready or resize $.fn.supersize = function() { //Invoke the resizenow() function on document ready $(document).ready(function() { $('#supersize').resizenow(); }); //Invoke the resizenow() function on browser resize $(window).bind("resize", function() { $('#supersize').resizenow(); $("#container").center(); }); }; //Adjust image size $.fn.resizenow = function() { //Define starting width and height values for the original image var startwidth = 1440; var startheight = 956; //Define image ratio var ratio = startheight/startwidth; //Gather browser dimensions var browserwidth = $(window).width(); var browserheight = $(window).height(); //Resize image to proper ratio if ((browserheight/browserwidth) > ratio) { $(this).height(browserheight); $(this).width(browserheight / ratio); $(this).children().height(browserheight); $(this).children().width(browserheight / ratio); } else { $(this).width(browserwidth); $(this).height(browserwidth * ratio); $(this).children().width(browserwidth); $(this).children().height(browserwidth * ratio); } //Make sure the image stays center in the window $(this).children().css('left', (browserwidth - $(this).width())/2); $(this).children().css('top', (browserheight - $(this).height())/2); }; })(jQuery);
dynamic css background for div element
hi, just wondering if there was a way of dynamically setting a background image for a div depending on the page you are on. there's no need to create a seperate template as the structure's exactly the same.
any help appreciated.
Hi Chloe, welcome to the Umbraco forum.
Take a look at the Dynamic Body Tag macro, you can apply CSS rules (for background-images) accordingly.
http://our.umbraco.org/projects/dynamic-body-tag
There are many other ways of doing what you want, but this is a good starting point.
Let us know how you get on.
Cheers, Lee.
i have done this on a few project... basically, use a media picker on the node.. for background image... and in your template, insert a macro that renders the div according... or you could use some inline xslt too... :)
on this site... http://test.mtturl.com i use some jquery to scale the backgound image...
here is my xslt macro...
and my template has this div and macro...
and using this jquery to do the supersizing :)
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.