javascript - Slide some contents of a page on load - Stack Overflow

I am totally new to jQuery and starting out basically so please forgive if this question sounds amateur

I am totally new to jQuery and starting out basically so please forgive if this question sounds amateurish or stupid. Any how I want to the header and footer of the page to remain static but the center contents of the page to slide in from the right side when page loads. Here is the page which does exactly that : flooring-by-design

I have looked into slide down function of jQuery and animate function but slidedown slides from top-bottom and I don't want that. What should I do?

My content goes like this:

<div class="container">
    <h1 class='logo'>Site Name</h1>
    <div class='bcontent'>
        <div id="one">One Content</div>
        <div id="two">Two</div>
        <div id="three">Three</div>
    </div>
    <footer>Copy rights</footer>
</div>

Div one two and three are the ones which I want to slide in nicely on page load. Just like the example link.

I am totally new to jQuery and starting out basically so please forgive if this question sounds amateurish or stupid. Any how I want to the header and footer of the page to remain static but the center contents of the page to slide in from the right side when page loads. Here is the page which does exactly that : flooring-by-design.

I have looked into slide down function of jQuery and animate function but slidedown slides from top-bottom and I don't want that. What should I do?

My content goes like this:

<div class="container">
    <h1 class='logo'>Site Name</h1>
    <div class='bcontent'>
        <div id="one">One Content</div>
        <div id="two">Two</div>
        <div id="three">Three</div>
    </div>
    <footer>Copy rights</footer>
</div>

Div one two and three are the ones which I want to slide in nicely on page load. Just like the example link.

Share Improve this question edited Jan 8, 2015 at 12:24 Harry 89.9k26 gold badges214 silver badges223 bronze badges asked Aug 12, 2013 at 10:41 Ahmar AliAhmar Ali 1,0788 gold badges28 silver badges53 bronze badges 3
  • you could also have a look at bxslider – Jake Aitchison Commented Aug 12, 2013 at 10:46
  • I think this question is what you're looking for. stackoverflow./questions/596608/slide-right-to-left – patricia Commented Aug 12, 2013 at 10:49
  • If I understand it properly it is a slider for image and content I don't want slider I only want to animate some content on page load @milkshake – Ahmar Ali Commented Aug 12, 2013 at 10:50
Add a ment  | 

2 Answers 2

Reset to default 2

You can do this using jQuery.

Basically the content is set at an offset of 800px from the left initially using CSS. Then using jQuery animate, we slide-in the contents till the offset from left is 0px. You can increase or decrease the duration to alter the speed of the slide-in.

jQuery

$(document).ready(function() {

    $("#one").animate({left: "0"}, {
    duration: 2000       
    });
    $("#two").animate({left: "0"}, {
    duration: 2250
    });
    $("#three").animate({left: "0"}, {
    duration: 2500        
    });
});

CSS

.bcontent > div{
    position: relative;
    display: inline-block; /* to display the 3 div's in same line */
    height: 200px; /* height, width and border just added for demo, not mandatory */
    width: 100px;
    border: 1px solid black;
    left: 110%; /* Added to avoid the width issue pointed out by DRP96 */
}
.bcontent{
    width: 100%;
    overflow: hidden; /* added to make the content hidden initially and avoid scroll-bar */
}

$(document).ready(function() {
  $("#one").animate({
    left: "0"
  }, {
    duration: 2000
  });
  $("#two").animate({
    left: "0"
  }, {
    duration: 2250
  });
  $("#three").animate({
    left: "0"
  }, {
    duration: 2500
  });
});
footer {
  bottom: 0px;
  font-size: 20px;
}
.bcontent {
  width: 100%;
  overflow: hidden;
}
.bcontent > div {
  position: relative;
  display: inline-block;
  height: 200px;
  width: 100px;
  left: 110%;
  border: 1px solid black;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div class="row">

  <h1 class='logo'>Site Name</h1>

  <div class='bcontent'>
    <div id="one" class="span4">One Content</div>
    <div id="two" class="span4">Two</div>
    <div id="three" class="span4">Three</div>
  </div>
  <footer>Copy rights</footer>
</div>

<div class="container">
<h1 class='logo'>Site Name</h1>

<div class='bcontent'>
<div id="one">One Content</div>
<div id="two">Two</div>
<div id="three">Three</div>
 </div>

<footer>Copy rights</footer>

 </div>

for the above html you can refer to the **demo

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745573140a4633803.html

相关推荐

  • javascript - Slide some contents of a page on load - Stack Overflow

    I am totally new to jQuery and starting out basically so please forgive if this question sounds amateur

    15小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信