展开/收缩DIV层面板(Open/Close Div Layers)

Open/Close Div Layers

This code snippet demonstrates using a 'container' div, which can be expanded or collapsed to show/hide blocks of content.

For my javascript function names, I pondered items that are opened and closed. I considered eyes, cupboards, drawers, even silly sock hand puppets, but finally decided upon a lunchbox. If I were a betting man, I'd be willing to bet that everyone who sees this webpage has owned, or at least seen, a lunchbox. Purt' near 70 years have passed since I was a lunchbox-toting lad, but I vaguely recall my favorite lunchbox - it was a real dandy depicting a team of superheroes known as The Herculoids. I was particularly fond of Gloop and Gleep, those darn cute little blobby things. But I digress...

Pack the Lunchbox (HTML)

First, we'll create the HTML, consisting of a pair of <div> layers for each lunchbox. The first <div> layer (clasp_x) will use a hyperlink to trigger our javascript function that displays the contents of the second <div> (lunch_x). I've supplied the code for two lunchboxes below, but you can add as many more as you like, by incrementing the numeric suffix (x) of each pair of layer id's. Now you can add this HTML code to your page:

 

 

Hide the Lunchbox (CSS)

Next, we'll create a couple of CSS classes, one of which will hold the hyperlink, and another whose contents are initially not displayed on the web page. Add these class definitions to your CSS stylesheet:

 

 

 

Open & Close the Lunchbox (javascript)

All that remains is to define two javascript functions - lunchboxOpen() and lunchboxClose() - which can be either in the <head> area of your HTML page, or in a separate javascript file:

 

 

 

 

Because of lacking time , I didn't translate it into Chinese. But the sentences did not difficult for reading. Someday,  I would have much spare time, and I will translate it then. Sorry.

 

 

If you want to see some examples of these codes, you can pay a visit to this address:

http://www.brenz.net/snippets/open_close_div.asp

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值