Css background image move

I have an image in the website header as a background. Now that the page has loaded, I would like to slowly move it from left to right (about 100 pixels) and then stop. Is there a not-too-complicated way to do this?

+3
source share
4 answers

jQuery lets you do this easily.

$("#theImage").animate({
    left: "+=100px", 
}, "slow");
+2
source

You should check that it is displayed only when the first page loads, and not on internal links to the site. I like using jquery for this kind of thing.

// animate on first load only
if ( document.referrer == null || document.referrer.indexOf(window.location.hostname) < 0 ) {
$("#logo").animate({ 
    marginLeft: "100px",
    easing: 'swing'
}, 3000 );  // adjust your duration here (milliseconds)
} else { 
    // internal site link set the proper position
    $("#logo").css({ marginLeft: "100px"});
}
+2
source

, ghoppe! . , , css:

.top-back-image { background-position: -100px 0px; }

jQuery:

$(".top-back-image").animate({ 
  backgroundPosition: "0px 0px",
  easing: 'swing'
}, 3000 );
+2

The guys at LaunchList have a moving background. Looking through their CSS, this is what I found. Maybe this will help.

#clouds {
    width: 100%;
    height: 650px;
    top: 200px;
    display: block;
    position: fixed;
    background: url(../art/cloud.png) 500px 0 repeat-x;
    -webkit-animation-name: move;
    -webkit-animation-duration: 400s;
    -webkit-animation-iteration-count: infinite;
    z-index: 2;
}

Please note that this will only be displayed for web browsers.

+1
source

Source: https://habr.com/ru/post/1750333/


All Articles