Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Functions.php:
- function add_parallax($post) {
- $parallax = "<div id='parallax-banner'>";
- $parallax .= get_the_post_thumbnail( $post, 'full' );
- // $parallax .= "<span class='title'>".get_the_title($post)."</span>";
- $parallax .= "</div>";
- echo $parallax;
- }
- CMS Control PHP code:
- <?php
- if( is_singular() ) {
- add_parallax($parallax[0]->ID);
- }
- ?>
- <script>
- jQuery(window).load(function(){
- var $banner = jQuery("#parallax-banner"), $image = $banner.find("img"), height = 0, max = 0;
- //let's find the best height for it
- height = $banner.find("img").height() / 3;
- $banner.height(height);
- //this is the maxiumum amount of scroll for still visible banner, cached to improve performance
- max = ($banner.offset()).top + height;
- //let's position our title in the middle of the Area
- $banner.find(".title").css({
- "top": ((height - $banner.find(".title").height()) / 2) + "px"
- });
- jQuery(window).scroll(function() {
- parallax_image(max, $image);
- });
- });
- function parallax_image(max, $image) {
- var imgTop = 0, scrollPos = jQuery(this).scrollTop();
- //rule of thirds to find the new top position for image
- imgTop = (scrollPos / max) * (2/3) * $image.height();
- $image.css({
- "top": -(imgTop)+"px"
- });
- }
- </script>
- CMS Control CSS Code:
- #parallax-banner {
- position: relative;
- width: 100%;
- margin-left: 0;
- overflow: hidden;
- }
- #parallax-banner img {
- position: absolute;
- }
- #parallax-banner .title {
- position: absolute;
- padding: 5px 0;
- top: 0;
- left: 0;
- width: 100%;
- text-align: center;
- text-transform: uppercase;
- font-weight: bold;
- background-color: transparent;
- background-color: rgba(255, 255, 255, 0.8);
- -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#ccffffff,endColorstr=#ccffffff)";
- -moz-box-shadow: 0 0 4px #000;
- -webkit-box-shadow: 0 0 4px #000;
- box-shadow: 0 0 4px #000;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement