centering fluid background image? css/jquery
-
Sorry if this is super basic (first time in the forums, setting up a site for a nonprofit) but I’ve tried a bunch of different plugins, searched for a while, and can’t quite get any to do what I want with the theme I purchased.
What I’m after is simply this: add one background image to the entire site that is vertically aligned to the top and horizontally centered, regardless of browser size. I do not want the image to resize, any horizontal excess can just be hidden.
The theme I’m using is Accende, by wpaddicts, which had the built in wordpress background support disabled. I tried enabling that, but the image didn’t show up (some other code over-riding?) so I started trying various plugins. Here’s the plugin/code I’ve been messing with:
<?php /** * @package Full screen background * @version 0.6 */ /* Plugin Name: Full screen background Plugin URI: http://www.trappers.tk/share/fullbg.zip Description: Full screen background, like the google home page Author: Jeroen Trappers Version: 0.5 Author URI: http://blog.trappers.tk */ function wp_full_bg() { ?> <!-- Change the src attribute of the img tag just below here to point to the image you want to use. --> <img id="wpfullbg" src="http://www.peterandjohn.org/wp-content/uploads/2013/01/site-wallpaper.jpg" > <script>window.jQuery || document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"><\x3C/script>')</script> <script type="text/javascript" language="javascript"> jQuery(function() { fullbg(); // jQuery(window).resize(fullbg); setTimeout(fullbg, 500); }); function fullbg() { var imgw = jQuery('#wpfullbg').width(); var imgh = jQuery('#wpfullbg').height(); var vpw = jQuery(window).width(); var vph = jQuery(window).height(); var imgratio = imgw / imgh; var viewportratio = vpw / vph; var w = vpw; var h = vph; if( viewportratio > imgratio ) { // screen is wider than picture -> increase the height of the picture; h = w / imgratio; } else { w = h * imgratio; } jQuery('#wpfullbg').css( { // 'left': '0pt', 'align': 'center', 'width': 1903, 'height': 995, 'overflow': 'hidden', 'z-index': '-2', 'top' : '0px', 'position' : 'fixed', 'opacity' : '0.999999999' } ); } </script> <?php } add_action( 'wp_footer', 'wp_full_bg' ); ?>
Any help is greatly appreciated, thank you! Website is peterandjohn.org
- The topic ‘centering fluid background image? css/jquery’ is closed to new replies.