admin管理员组文章数量:1022476
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
2 Answers
Reset to default 2You 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
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
2 Answers
Reset to default 2You 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
本文标签: javascriptSlide some contents of a page on loadStack Overflow
版权声明:本文标题:javascript - Slide some contents of a page on load - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745573138a2156858.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论