
jQuery tutorial
Usiamo alcune semplici funzioni di jquery per creare alcuni effetti di sicuro successo.
Realizziamo un semplice javascript che ci permetterà di far comparire e scomparire alcune slide a seconda del pulsante premuto, in seguito ricliccando sul pulsante torneremo alla fase iniziale.
Let’s start designing our html, what we want is a simple structure made of a div containing our buttons, we will use some image as buttons, and the section we want to hide/unhide.
<div id=”image_catalogo”>
<img src=”images/marketing.jpg” class=”imgcatalogo” align=”middle” alt=”Marketing” title=”Marketing” name=”Marketing” id=”marketing_catalogo” />
<img src=”images/siti-web.jpg” class=”imgcatalogo” align=”middle” alt=”Web Site” title=”Web Site” name=”Web Site” id=”website_catalogo” />
<img src=”images/software.jpg” class=”imgcatalogo” align=”middle” alt=”Software” title=”Software” name=”Software” id=”software_catalogo” />
</div>
<div id=”marketing-text” class=”catalogo-text” style=”display:none;”>Section 1 Marketing</div>
<div id=”website-text” class=”catalogo-text” style=”display:none; “>Section 2 Web Site</div>
<div id=”software-text” class=”catalogo-text” style=”display:none;”>Section 3 Software</div>
</div>
As you can see we have created a container whose id is catalogo_description and 4 child:
- id: image_catalogo => this div contain our menu, in this example it consist in 3 images
- id: marketing-text => this div contain our first section
- id: website-text => this div contain our second section
- id: software-text => this div contain our third section
We have included some default style in our section “display:none;” this cause javascript have problem in changing the display properties inside an externalCSS
Let’s add some CSS style to this you can add it inside an external CSS as in a style tag in your html.
position: absolute;
}
#website_catalogo{
left: 2%;
z-index: 0;
}
#software_catalogo {
left:50%;
margin-left: -100px;
z-index: 1;
}
#marketing_catalogo{
left:98%;
margin-left: -200px;
z-index: 2;
}
#image_catalogo {
width: 240px;
height: 500px;
float:left;
text-align:center;
}
.catalogo-text {
position:absolute;
z-index: -1;
padding-left: 250px;
}
As you can see it’s a simple formatting css, the only important properties are the absolute positioning of the element.
Now we can add our effect.
var detailed = false;
var interrupt;
$(’.imgcatalogo’).click(function() {
if (detailed == false) {
detailed = true;
clearTimeout ( interrupt );
$(”.imgcatalogo:not(#” + $(this)[0].id + “)”).animate({
left: ‘2%’,
marginLeft: ‘0px’
}, 1500 );
$(”.imgcatalogo:not(#” + $(this)[0].id + “)”).slideUp();
$(this).animate({
left: ‘2%’,
marginLeft: ‘0px’
}, 3000 );
interrupt = setTimeout(’ $(”#’ + $(this)[0].id.replace(”_catalogo”, “-text”) +’”).slideDown(”fast”)’, 3000);
}
else {
detailed = false;
clearTimeout ( interrupt );
$(’.catalogo-text’).slideUp();
$(”.imgcatalogo:not(#” + $(this)[0].id + “)”).slideDown(”fast”);
$(”img#marketing_catalogo”).animate({
marginLeft: ‘-200px’,
left: ‘98%’
}, 1500 );
$(”img#website_catalogo”).animate({
left: ‘2%’
}, 1500 );
$(”img#software_catalogo”).animate({
left: ‘50%’,
marginLeft: ‘-100px’
}, 1500 );
$(”.imgcatalogo”).slideDown(”fast”);
}
});
</script>
Let’s explain what we do.
First we create a var “detailed” this is usefull to store the state of the page, it say if we have just opened a section or if the sections are all closed.
Next we associate an onclick event to the “imgcatalogo” class.
At first we want to make all the buttons exept the one clicked to disappear, thi is done easily with the SlideUp function of jquery, as selector for this effect we want all the elements that has class “imgcatalogo” except the one clicked, well we have the id of the clicked one so it’s easy :
Why not add a special effect before the slide? lets move all the image not clicked to the left side and then made ‘em disappear:
left: ‘2%’,
marginLeft: ‘0px’
}, 1500 );
This line remove the css property margin-left and set the position to left 2%, it takes 1,5 sec to do it so we will be able to see the moving elements.
Let’s move the one clicked too but slowly so we can see what’s appening:
left: ‘2%’,
marginLeft: ‘0px’
}, 3000 );
Now we want to make our section appear, well of course we have to wait till the effect for the images are over, let’s use a timer so:
The id of the section is the same as the id of the image clicked except the last word, we made it SlideDown fast.
Ok now the first half of our javascript is over, let’s see how to make the section disappear and the button come back at their position.
Now it comes to hand the “detailed” var so we can know in which of the two cases we are, show the section or hide it.
First of all we want the section to disappear, we can use the slideUp effect as before:
Next we want the image to comeback so we made them slideDown:
And finally we restore the CSS as it was at start:
marginLeft: ‘-200px’,
left: ‘98%’
}, 1500 );
$(”img#website_catalogo”).animate({
left: ‘2%’
}, 1500 );
$(”img#software_catalogo”).animate({
left: ‘50%’,
marginLeft: ‘-100px’
}, 1500 );
Demo here
Update 11/04/2209 – We have modified some line of code to make it more solid since there was problem if you click on image while they are moving, the line modified are in bold character.








not very obvious how to get back to the whole menu, but apart from that looks good
yes commonly we put an help on top like “click on image to enter section, click on image to get back to menu”
Very Impressive. A lot of possibilities for this, especially for content.
[...] Home Page Update > abbiamo aggiornato l’home page di webair.it rendendo più semplice l’accesso ad alcune aree principali del sito, infatti nel riquadro “In Evidenza” compaiono ora 3 blocchi: L’Essenza del Web, Offerte e Grafiche Pubblicitarie. Tra queste la novità più grande è il catalogo, finalmente completo di prezzi e facilmente accessibile. E’ stato realizzato utilizzando la tecnica jQuery descritta ieri (Slide and hide Section with jQuery). [...]
I love the effect, however, the way you are using it is not usable/user friendly at all.
@ Kristy > it’s only an example, you can personalize it as you prefer. We have used this effect in our catalog page http://www.webair.it/catalogo.html with an help on top “click on image to enter section, click on image to get back to menu”
Not bad, but I think it must be do better
I don’t find it very usable. Even with the text helps (like your catalogue)
The main problem beeing that if you want to navigate, from page1 to page2, you need 2 clicks.
1 to display menu, 1 to navigate.
And really not a very intuitive process…
Click on the current location ‘icon’ to move to another… hmm.. a little like click on the button reading “start” when you want to stop your machine. :p
But animation itself is interresting indeed. Giid piece of work.
@ Roni > thanks for your suggestion, this is just an example, the design and the usability are customizable. Probably in future we’ll change our catalogue improving the usability.
[url=http://cstatman.blogspot.com/2004_07_01_archive.html]Hello[/url] !Oh hubba hubba! Forget the sportscar, been there, done that, got the T shirt, wore it out, gave it to goodwill.
http://cstatman.blogspot.com/2004_07_01_archive.html
hi
is it free,if it is free ,where i can download the script (js files)
I am waiting for your great response.
Thanks
Venkat
@ venkat > you must just read and copy the code, there is not a link for the download.
Dear Sir,
I am using below code.Everything is ok ,but i am not able to slide and hide the images.Please can you guide me how implement.I am using Visval Studio.net 2005
Untitled Page
body {
background-color: black;
color: white;
}
.imgcatalogo {
position: absolute;
}
#website_catalogo{
left: 2%;
z-index: 0;
}
#software_catalogo {
left:50%;
margin-left: -100px;
z-index: 1;
}
#marketing_catalogo{
left:98%;
margin-left: -200px;
z-index: 2;
}
#image_catalogo {
width: 240px;
height: 500px;
float:left;
text-align:center;
}
.catalogo-text {
position:absolute;
z-index: -1;
padding-left: 250px;
}
Back to blog
Section 1 Marketing
Section 2 Web Site
Section 3 Software
var detailed = false;
var interrupt;
$(’.imgcatalogo’).click(function() {
if (detailed == false) {
clearTimeout ( interrupt );
detailed = true;
$(”.imgcatalogo:not(#” + $(this)[0].id + “)”).animate({
left: ‘2%’,
marginLeft: ‘0px’
}, 1500 );
$(”.imgcatalogo:not(#” + $(this)[0].id + “)”).slideUp();
$(this).animate({
left: ‘2%’,
marginLeft: ‘0px’
}, 3000 );
interrupt = setTimeout(’ $(”#’ + $(this)[0].id.replace(”_catalogo”, “-text”) +’”).slideDown(”fast”)’, 3000);
}
else {
detailed = false;
clearTimeout ( interrupt );
$(’.catalogo-text’).slideUp();
$(”.imgcatalogo:not(#” + $(this)[0].id + “)”).slideDown(”fast”);
$(”img#marketing_catalogo”).animate({
marginLeft: ‘-200px’,
left: ‘98%’
}, 1500 );
$(”img#website_catalogo”).animate({
left: ‘2%’
}, 1500 );
$(”img#software_catalogo”).animate({
left: ‘50%’,
marginLeft: ‘-100px’
}, 1500 );
$(”.imgcatalogo”).slideDown(”fast”);
}
});
Thanks
Venkat
Check if the html you used is correct (div and image must have an id corresponding to that writed in js), if still it didn’t work check if your html is well formed, if it’s validated then the code should work
Hi,
Thanks alot.It is working fine I have done.
Thanks,
Venkat
[...] Documentation: http://www.webair.it/blog/2009/03/11/slide-and-hide-section-with-jquery/ [...]
[...] Slide and hide section with jquery (16) [...]
Oh, Thanks man, Good tut
I got this to work but I have a problem. In Firefox the content to the right of the picture cannot be selected. I noticed that on http://www.webair.it/catalogo.html once an image slides out the content is selectable. How do I get it to work?
Hi,
good work. We combine it with some other scripts. I just miss a method to call also a selected state – perhaps you can add this in your tutorial. We have a common start page, but a link to chapter 1-3 (like your work) would be nice.
Thanks.
Oh, Thanks man, Good .. Thanks alot.It is working fine I have done.
Thanks,
[...] the menu items slide in and then hide themselves elegantly to give way for the selected menu item. Web Site Demo Download AKPC_IDS += "493,";Popularity: unranked [?] Share and [...]
[...] 9)Slide and hide with jQuery [...]
thanks man, i have one question tho, how do i make the content on the right selectable or usable? i’m making a site with the 3rd panel as my registration form but i can’t select anything.
Karamba!, benicar side effects, %-]]], erythromycin base pd 500mg, oemtz, Spectrobid, 689, buy cheapest acomplia, 314, levitra online, 8-((, allopurinol, 691, buy cialis wholesale, phxix, strattera adults, 182267, buy erythromycin, %-), herpes valtrex,
PP, riobant, 121595, lasix, kdg, accutane, ychxx, cipro, =[[[, contents of cipro, =-PP, buy strattera, %-D, drug glucophage loss weight, ynf, prednisolone for dog, uusq, retin a without prescription, 3374, use of valtrex, 872415, side effects of benicar, >:))), doxycycline, eptb,
alabanza de pentecostes
1000 yard 300 win mag
amana furnace problems
alpo prison sentence
1996 yukon pulley diagram
98 mauser parts
300ossm load data
a homeade suppresser
1000 kilograms equals
aqueduct fleemarket
a homeade suppresser
5th chapter mc club
38 taurus snub nose handgun
adult stores
adult nursing relationship
adornos para bizcochos
23 grams of liquid
10 milliliters is
a fib with rvr
12 ga rifled slug ballistics
Very good plugin ремонт мобильных телефонов