I'm using a JQuery function to slide a div into and out of visibility, but every time I toggle, the browser resets my view to the top of the web page..
What I want to happen is when you click to reveal the div, the page scrolls down and the div content is in full view. When I click again to re-hide the div, I want the page to scroll back up smoothly instead of just reverting to the top of the whole page...
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
//toggle the componenet with class msg_body
jQuery(".heading").click(function()
{
jQuery(this).next(".content").slideToggle(500);
});
});
</script>
and on the page:
Code:
<div class="heading">
<h2><a href="#">check out our work</a></h2>
<a href="#"><img src="images/downarrow.png" alt="downarrow" /></a>
</div>
<div class="content">
<p>Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui. Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus.</p>
</div>
That way, the div slides down, then it scrolls down nicely. If you want a good plugin, let me know what you think of this: www.passmethatspanner.com/home.php and I'll send it to you.
Try it without the scrolling, see if the slideDown works for you, make sure the CSS says display:hidden; and you need to try an find a plugin for the smoothscrolling. I'll try and find one for you.
Thanks DangerousPrince, here's what I have so far..
Code:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8" />
<title>new IG site</title>
<LINK REL=StyleSheet HREF="style.css" TYPE="text/css" MEDIA=screen>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
//toggle the componenet with class msg_body
jQuery(".heading").click(function()
{
jQuery(this).next(".content").slideDown(500);
});
});
/*
$(document).ready(function() {
$(".content").slideDown(500).jQueryPluginScroll("meh");
});*/
</script>
</head>
<body>
<div id="wrapper">
<div id="leftwrapper">
<header>
<h1><img src="images/iglogo2.png" alt="Impact Group" /></h1>
</header>
<aside>
<div class="separator"></div>
<ul>
<li><h2>marketing/</h2>
<ul>
<li><h3>branding/</h3></li>
<li><h3>design/</h3></li>
<li><h3>advertising</h3></li>
</ul>
</li>
<li><h2>web/</h2>
<ul>
<li><h3>design/</h3></li>
<li><h3>programming/</h3></li>
<li><h3>management</h3></li>
</ul>
</li>
<li><h2>training/</h2>
<ul>
<li><h3>leadership/</h3></li>
<li><h3>supervising/</h3></li>
<li><h3>marketing</h3></li>
</ul>
</li>
<li><h2>coaching/</h2>
<ul>
<li><h3>strategy/</h3></li>
<li><h3>structure/</h3></li>
<li><h3>staff</h3></li>
</ul>
</li>
<li><h2>facilitation/</h2>
<ul>
<li><h3>events/</h3></li>
<li><h3>workshops/</h3></li>
<li><h3>meetings</h3></li>
</ul>
</li>
</ul>
<div class="separator"></div>
<div class="heading">
<h2><a href="#">who the heck are we?</a></h2>
<a href="#"><img src="images/downarrow.png" alt="downarrow"/></a>
</div>
<div class="content">a bit about us and why we do what we do</div>
<div class="separator"></div>
<div class="heading">
<h2><a href="#">check out our work</a></h2>
<a href="#"><img src="images/downarrow.png" alt="downarrow" /></a>
</div>
<div class="content">
<p>Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui. Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus.</p>
</div>
</aside>
<!--<footer>
copyright Impact Group 2011
</footer>-->
</div> <!--end #leftwrapper div-->
<div id="rightcontent">
<p>Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui. Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus.</p><p>Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui. Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus.</p><p>Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.</p>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui. Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Nulla vitae elit libero, a pharetra augue. Donec id elit non mi porta gravida at eget metus.</p>
</div>
</div> <!--end #wrapper div-->
</body>
</html>
Okay, well the jQuery I wrote needs to be edited, it was merely an example once you've found a plugin. The script you have works correctly, all you need now is to add the scroll script.
$('.scrollPage').click(function() {
var elementClicked = $(this).attr("href");
var destination = $(elementClicked).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
return false;
});
What I don't understand is how to integrate this with the other Jquery I have which is:
Code:
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(".content").hide();
//toggle the component with class msg_body
jQuery(".heading").click(function()
{
jQuery(this).next(".content").slideDown(500);
});
});
I get that this hides then shows my content, and I get that the other script I found can be used to make the page scroll down... but how do I make them both work on the same thing at the same time?
Bookmarks