Making first item visible when loaded.

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

17-Jul-12 17:37
I am playing around with some jQuery.

3 menu items, when you click on a menu item the content fades in.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">

#wrap { width: 920px; padding: 20px; position: relative; margin: 0 auto; overflow: hidden; color: #333; background-color: #fff; }
#ajax { width: 400px; padding: 20px; }
.loader { border: 0 none; float: left; clear: both; margin: 100px 0 0 200px; }
</style>
<link rel="stylesheet" href="default.css" type="text/css" media="screen" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="slide-fade-content.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.more').live('click',function(){

var href = $(this).attr('href');
if ($('#ajax').is(':visible')) {
$('#ajax').css('display','block').animate({height:'1px'}).empty();
}
$('#ajax').css('display','block').animate({height:'500px'},function(){
$('#ajax').html('<img class="loader" src="loader.gif" alt="">');
$('#ajax').load('slide-fade-content.html #'+href,function(){
$('#ajax').fadeIn().highlightFade({color:'rgb(253,253,175)'});
});
});
return true;
});
});
</script>
</head>
<body>
<div id="outer">
<div id="logo">

</div>
<div id="container">

<div id="menu">
<ul>
<li><a class="more" href="#first-item">First Item</a></li>
<li><a class="more" href="#second-item">Second Item</a></li>
<li><a class="more" href="#third-item">Third Item</a></li>
</ul>
</div>
<div id="ajax"></div>
<div id="menubottom"></div>

</div>
</div>

</body>
</html>


Its a bit messy, but what I would like to know is can I not add a line of jQuery to make "#first-item" load its content, at the moment it is hidden.



$('.more').live('click',function(){

var href = $(this).attr('href');
if ($('#ajax').is(':visible')) {


Can I not duplicate this and say $('.more #first-item') ? Still pretty hard getting to grips with the logic of jQuery.

Should I not be telling jQuery to .load the #first-item ?
21-Jul-12 12:07
Use the body.onLoad event to trigger the event.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
25-Jul-12 13:45
Thanks for the help, still a bit lost... but I am reading the jQuery site to try and get to grips with jQuery.

Thanks any way.

Peace.
25-Jul-12 17:25
I gave up trying to figure out jQuery and MooTools, it was just so much simpler to write my own methods.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/

 
New posts
Old posts

Follow Elated