Adding parallax effect to Wordpress page - wordpress

I have a Wordpress website with an existing theme and content.
In one page I have a div with a video background and a text in the foreground.
I want to add a parallax effect by some jQuery code.
I can use Id's or classes to both of them if needed.
Can someone advice by a reference to code or to a relevant tutorial?

This is available in w3schools.com
<style>
.parallax {
/* The image used */
background-image: url("img_parallax.jpg");
/* Set a specific height */
height: 500px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
</style>
<!-- Container element -->
<div class="parallax"></div>

This website is your answer :
http://scrollmagic.io/examples/advanced/parallax_sections.html
Try checking their examples and implement them in your website. Make sure you are using the related IDs and Classes properly.

Related

How do I add a background image to the home page only?

I'm finding it difficult to insert my background image only on the home page. I have 6 pages but I only want the background image to be on the home page. Annoyingly the background image is on all of my 6 pages. Any help would be appreciated , thank you.
header {
background-image: url(img/markus-spiske-PIJwPMtzBI0-unsplash.jpg);
background-size: cover;
background-position: center;
margin-top: 200px;
height: 100vh;
background-attachment: fixed;
}
That is because your header tag in the CSS file will always get called on the no matter the page it is.
To solve this, you need to give your header an extra "name" so to speak. In this case giving it an "id" is enough.
#homepage-header{
background-image: url('path/to/image')
}
//As you can see here, instead of calling the <header> im now calling the #homepage-header
<header id="homepage-header">
</header>
//I added a unique ID to <header> tag allowing me to target this header specificly on the homepage.
For sake of completeness, I will add this alternative solution.
If this is just for one or two exceptions, you could also inline the CSS code on the specific page where you want this image to display. Like this:
<div></div> <!-- this is the image div -->
<style>
header {
background-image: url(img/markus-spiske-PIJwPMtzBI0-unsplash.jpg);
background-size: cover;
background-position: center;
margin-top: 200px;
height: 100vh;
background-attachment: fixed;
}
</style>
This way, you can keep using the header selector for whatever you want, and only on that specific page, the header will use the above CSS code.

GIF Background Image not appearing on my page

I want to use a GIF file as a background image on my web page but its not working when I style it in CSS.
CSS
Body{
background-image: url("1554323659436.gif");
background-repeat: no-repeat;
background-size: 50% 50%;
content:white;
width: auto;
}
I have ensured the GIF name is accurate, but the image isn't appearing in the page's background. Can someone help out?
Hope this answer helps. From my experience, gif images or images in general fail to appear when folder structure is not defined properly. Please check a standard format for attaching gif or any image type in html background
body {
background-image: url("[path_to_image]/1554323659436.gif"); /* The image used */
background-color: #cccccc; /* Used if the image is unavailable */
height: 500px; /* You must set a specified height */
background-position: center; /* Center the image */
background-repeat: no-repeat; /* Do not repeat the image */
background-size: cover; /* Resize the background image to cover the entire container */
}
Please note, all of the other attributes can be optional except the first one. Good Luck!

filter:grayscale(100%) in IE 11 for images

I have searched all over the internet but I didn't get any solution.
Can anyone say what is the alternative for the css3 filter and for transistion3d in IE 11 and IE 12?
I don't want to use any Plugins.
Not for SVG
i want for <img> tag
Since filter is not supported with IE11 - there is ie hacks like this However it would have to include a lot of JS seen here which would mean writing browser detection in JS and more. -
You could try to add two kinds of images, one is the original image and another is a grayscale image. Then, using div to display these images. like this:
<style>
.grayscale {
background-image: url('images/Image1.jpg');
background-size: cover; /* <------ */
background-repeat: no-repeat;
background-position: center center;
}
.grayscale:hover {
background-image: url('images/imag1_gray.PNG') ;
background-size: cover; /* <------ */
background-repeat: no-repeat;
background-position: center center;
}
</style>
<div class="grayscale" style="width:500px; height:500px">
</div>
the result like this:
In my option, I prefer to use some JQuery plugin, like this.

Resize image dynamically with CSS

I'm reading news on this page mostly on my mobile device:
link
The big banner right of the logo is not scaling properly on the mobile device.
So when you resize the window and make it smaller everything is resizing except the banner.
Im learning php, css and just wondering how this could be solved. Ive checked also on stackoverflow and find something like:
img {
max-width: 100%;
height: auto;
width: auto\9; /* ie8 */ }
I've tried this also in the dev. mode of google chrome but it desnt work.
Is this solvable with the provided data from the dev mode?
Code looks like:
<div style="position:relative;
width:728px; height:90px; z-index:10;
background-image: url(http://www.image.jpg);">
Based on your code, the banner is implemented as background image, not an IMG element. To make background image scaled so that it's entirely visible, use background-size: contain. So your user styles could be like this:
.site-header-banner > DIV {
background-size: contain;
background-repeat: no-repeat; // To disable repeating background image.
max-width: 100%;
}
You can use it as a background with the following properties:
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
https://jsfiddle.net/alexndreazevedo/xe9tvkyr/
You can define a fixed size to DIV containing image background and change it by media query.

Stretch and scale a CSS image in the background - with CSS only

I want that my background image stretch and scale depending on the browser viewport size.
I've seen some questions on Stack Overflow that do the job, like Stretch and scale CSS background for example. It works well, but I want to place the image using background, not with an img tag.
In that one an img tag is placed, and then with CSS we tribute to the img tag.
width:100%; height:100%;
It works, but that question is a bit old, and states that in CSS 3 resizing a background image will work pretty well. I've tried this example the first one, but it didn't work out for me.
Is there a good method to do it with the background-image declaration?
CSS3 has a nice little attribute called background-size:cover.
This scales the image so that the background area is completely covered by the background image while maintaining the aspect ratio. The entire area will be covered. However, part of the image may not be visible if the width/height of the resized image is too large.
You could use the CSS3 property to do it quite nicely. It resizes to ratio so no image distortion (although it does upscale small images). Just note, it's not implemented in all browsers yet.
background-size: 100%;
Using the code I mentioned...
HTML
<div id="background">
<img src="img.jpg" class="stretch" alt="" />
</div>
CSS
#background {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1; /* Ensure div tag stays behind content; -999 might work, too. */
}
.stretch {
width:100%;
height:100%;
}
That produces the desired effect: only the content will scroll, not the background.
The background image resizes to the browser viewport for any screen size. When the content doesn't fit the browser viewport, and the user needs to scroll the page, the background image remains fixed in the viewport while the content scrolls.
With CSS 3 it seems this would be a lot easier.
CSS:
html,body {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover; /* For WebKit*/
-moz-background-size: cover; /* Mozilla*/
-o-background-size: cover; /* Opera*/
background-size: cover; /* Generic*/
}
background-size: 100% 100%;
stretches the background to fill the entire element on both axes.
The following CSS part should stretch the image with all browsers.
I do this dynamically for each page. Therefore I use PHP to generate its own HTML tag for each page. All the pictures are in the 'image' folder and end with 'Bg.jpg'.
<html style="
background: url(images/'.$pic.'Bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/'.$pic.'Bg.jpg\', sizingMethod=\'scale\');
-ms-filter: \"progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'images/'.$pic.'Bg.jpg\', sizingMethod=\'scale\')\
";>
If you have only one background picture for all pages then you may remove the $pic variable, remove escaping back-slashes, adjust paths and place this code in your CSS file.
html{
background: url(images/homeBg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/homeBg.jpg', sizingMethod='scale');
-ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/homeBg', sizingMethod='scale');
}
This was tested with Internet Explorer 9, Chrome 21, and Firefox 14.
Use this CSS:
background: url('img.png') no-repeat;
background-size: 100%;
You can actually achieve the same effect as a background image with the img tag. You just have to set its z-index lower than everything else, set position:absolute and use a transparent background for every box in the foreground.
You can add this class into your CSS file.
.stretch {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
It works in:
Safari 3 or later
Chrome Whatever or later
Internet Explorer 9 or later
Opera 10 or later (Opera 9.5 supported background-size, but not the keywords)
Firefox 3.6 or later (Firefox 4 supports non-vendor prefixed version)
It is explained by CSS tricks: Perfect Full Page Background Image
Demo: https://css-tricks.com/examples/FullPageBackgroundImage/progressive.php
Code:
body {
background: url(images/myBackground.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
In order to scale your images appropriately based on the container size, use the following:
background-size: contain;
background-repeat: no-repeat;
I use this, and it works with all browsers:
<html>
<head>
<title>Stretched Background Image</title>
<style type="text/css">
/* Remove margins from the 'html' and 'body' tags, and ensure the page takes up full screen height. */
html, body {height:100%; margin:0; padding:0;}
/* Set the position and dimensions of the background image. */
#page-background {position:fixed; top:0; left:0; width:100%; height:100%;}
/* Specify the position and layering for the content that needs to appear in front of the background image. Must have a higher z-index value than the background image. Also add some padding to compensate for removing the margin from the 'html' and 'body' tags. */
#content {position:relative; z-index:1; padding:10px;}
</style>
<!-- The above code doesn't work in Internet Explorer 6. To address this, we use a conditional comment to specify an alternative style sheet for IE 6. -->
<!--[if IE 6]>
<style type="text/css">
html {overflow-y:hidden;}
body {overflow-y:auto;}
#page-background {position:absolute; z-index:-1;}
#content {position:static;padding:10px;}
</style>
<![endif]-->
</head>
<body>
<div id="page-background"><img src="http://www.quackit.com/pix/milford_sound/milford_sound.jpg" width="100%" height="100%" alt="Smile"></div>
<div id="content">
<h2>Stretch that Background Image!</h2>
<p>This text appears in front of the background image. This is because we've used CSS to layer the content in front of the background image. The background image will stretch to fit your browser window. You can see the image grow and shrink as you resize your browser.</p>
<p>Go on, try it - resize your browser!</p>
</div>
</body>
</html>
I wanted to center and scale a background image, without stretching it to the entire page, and I wanted the aspect ratio to be maintained. This worked for me, thanks to the variations suggested in other answers:
INLINE IMAGE: ------------------------
<div id="background">
<img src="img.jpg" class="stretch" alt="" />
</div>
CSS ----------------------------------
html {
height:100%;
}
#background {
text-align: center;
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}
.stretch {
margin: auto;
height:100%;
}
Thanks!
But then it was not working for the Google Chrome and Safari browsers (stretching worked, but the hight of the pictures was only 2 mm!), until someone told me what lacks:
Try to set height:auto;min-height:100%;
So change that for your height:100%; line, gives:
#### #background {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1;
}
.stretch {
width:100%;
height:auto;
min-height:100%;
}
Just before that newly added code I have this in my Drupal Tendu themes style.css:
html, body{height:100%;}
#page{background:#ffffff; height:auto !important;height:100%;min-height:100%;position:relative;}
Then I have to make a new block within Drupal with the picture while adding class=stretch:
< img alt="" class="stretch" src="pic.url" />
Just copying a picture with the editor in that Drupal block doesn't work; one has to change the editor to non-formatted text.
I agree with the image in absolute div with 100% width and height. Make sure you set 100% width and height for the body in the CSS and set margins and padding to zero. Another issue you will find with this method is that when selecting text, the selection area can sometimes encompass the background image, which has the unfortunate effect of making the full page have the selected state. You can get round this by using the user-select:none CSS rule, like so:
<html>
<head>
<style type="text/css">
html,body {
height: 100%;
width: 100%
margin: none;
padding: none;
}
#background {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -99999;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
#background img {
width: 100%;
height: 100%;
}
#main{ z-index:10;}
</style>
</head>
<body>
<div id="main">
content here
</div>
<div id="background"><img src="bg.jpg"></div>
</body>
</html>
Again, Internet Explorer is the bad guy here, because it doesn't recognise the user-select option - not even Internet Explorer 10 preview supports it, so you have the option of either using JavaScript to prevent background image selection (for example, http://www.felgall.com/jstip35.htm ) or using CSS 3 background-stretch method.
Also, for SEO I would put the background image at the bottom of the page, but if the background image takes too long to load (that is, with a white background initially), you could move to the top of the page.
I used a combination of the background-X CSS properties to achieve the ideal scaling background image.
background-size: cover;
background-repeat: no-repeat;
background-position: center;
background-attachment: fixed;
This makes the background always cover the entire browser window and remains centered when scaling.
Use the Backstretch plugin. One could even have several images slide. It also works within containers. This way for example one could have only a portion of the background been covered with an background image.
Since even I could get it to work proves it to be an easy to use plugin :).
The following worked for me.
.back-ground {
background-image: url("../assets/background.png");
background-size: 100vw 100vh;
}
that worked to cover the entire background on different dimensions
If you want to have the content centered horizontally, use a combination like this:
background-repeat: no-repeat;
background-size: cover;
background-position: center;
This will look beautiful.
Use this CSS:
background-size: 100% 100%
You can use the border-image : yourimage property to scale the image up to the border. Even if you give the background-image, the border image will be drawn over it.
The border-image property is very useful if your style sheet is implemented somewhere which doesn't support CSS 3. If you are using Google Chrome or Firefox, then I recommend the background-size:cover property itself.
Do you want to achieve this just using one image? Because you can actually make somewhat similar to a stretching background using two images. PNG images for instance.
I've done this before, and it's not that hard. Besides, I think stretching would just harm the quality of the background. And if you add a huge image it would slow down slow computers and browsers.

Resources