标签:
![]() ![]() ![]() |
function ShowImage(page, tag)
...{
var i = 1;
var el;
while (el = document.getElementById(tag + i)) ...{
if (i == page)
el.style.display = ‘block‘;
else
el.style.display = ‘none‘;
i++;
}
}
<table>
<tr valign="top">
<td>
<div style="display:block" id="image1">
<img src="/onlamp/2007/08/23/graphics/pic1.jpg" />
</div>
<div style="display:none" id="image2">
<img src="/onlamp/2007/08/23/graphics/pic2.jpg" />
</div>
<div style="display:none" id="image3">
<img src="/onlamp/2007/08/23/graphics/pic3.jpg" />
</div>
</td>
<td width="100%" align="right">
<select onchange="ShowImage(parseInt(this.value), ‘image‘);">
<option selected="selected" value="1">Image 1</option>
<option value="2">Image 2</option>
<option value="3">Image 3</option>
</select>
</td>
</tr>
</table>
Introducing the new, improved multi-widget. It slices, it dices, it even does your taxes! Order yours today! Call now: 555-WIDG
The multi-widget is a sophisticated piece of complex machinery designed by the country‘s leading nuclear physicists. Order yours today and you will quickly learn how easy it is to do just about anything in no time, thanks to our patented EZ-Widge technology. Motor: 5HP
|
<div style="display:block" id="tab1">
<ul class="tab">
<li class="tab_selected" onclick="ShowImage(1, ‘tab‘);">
Summary
</li>
<li onclick="ShowImage(2, ‘tab‘);">
Details
</li>
<li onclick="ShowImage(3, ‘tab‘);">
Known Issues
</li>
</ul>
<p>
Introducing the new, improved multi-widget. It slices, it dices, it even does
your taxes! Order yours today! Call now: 555-WIDG
</p>
</div>
<div style="display:none" id="tab2">
<ul class="tab">
<li onclick="ShowImage(1, ‘tab‘);">
Summary
</li>
<li class="tab_selected" onclick="ShowImage(2, ‘tab‘);">
Details
</li>
<li onclick="ShowImage(3, ‘tab‘);">
Known Issues
</li>
</ul>
<p>
The multi-widget is a sophisticated piece of complex machinery designed by the
country‘s leading nuclear physicists. Order yours today and you will quickly
learn how easy it is to do just about anything in no time, thanks to our patented
EZ-Widge technology.
</p>
<p>
Motor: 5HP<br />
Dimensions: 8" x 5" x 2"<br />
Weight: 212 g<br />
Radioactivity: negligible
</p>
</div>
<div style="display:none" id="tab3">
<ul class="tab">
<li onclick="ShowImage(1, ‘tab‘);">
Summary
</li>
<li onclick="ShowImage(2, ‘tab‘);">
Details
</li>
<li class="tab_selected" onclick="ShowImage(3, ‘tab‘);">
Known Issues
</li>
</ul>
<ul>
<li>Do not use multi-widget near open flames</li>
<li>Do not run while holding multi-widget</li>
<li>Do not taunt multi-widget</li>
<li>
Multi-widget may, under certain as yet undetermined circumstances,
spontaneously explode. We hereby disclaim any libaility for personal injury
caused as a result of multi-widget; for your safety, we recommend wearing
body armor while handling multi-widget.
</li>
</ul>
</div>
ul.tab {...}{
margin: 0;
padding: 3px 0;
border-bottom: 1px solid #778;
font-weight: bold;
}

ul.tab li {...}{
display: inline;
padding: 3px 0.5em;
margin-left: 3px;
border-top: 1px solid #778;
border-left: 1px solid #778;
border-right: 1px solid #778;
border-bottom: none;
background: top repeat-x #89aac7;
white-space: nowrap;
color: white;
cursor:pointer;
}

ul.tab li.tab_selected {...}{
background: #fff;
border-bottom: 1px solid #fff;
color: black;
} |
Choice of four widget colors |
|
|
<div style="display:block;" id="colors1">
<table style="background:#eeeebb">
<tr>
<td>
<img src="/onlamp/2007/08/23/graphics/expand.jpg" style="cursor:pointer;"
alt="Click to Expand" title="Click to Expand" onclick="ShowImage(2, ‘colors‘);" />
</td>
<td>
Choice of four widget colors
</td>
</tr>
</table>
</div>
<div style="display:none;" id="colors2">
<table style="background:#eeeebb">
<tr valign="top">
<td>
<img src="/onlamp/2007/08/23/graphics/collapse.jpg" style="cursor:pointer;"
alt="Click to Collapse" title="Click to Collapse" onclick="ShowImage(1, ‘colors‘);" />
</td>
<td>
<ul>
<li>blue</li>
<li>green</li>
<li>red</li>
<li>brown</li>
</ul>
</td>
</tr>
</table>
</div>| John |
| Jane |
| Bill |
// Set the callbacks
document.onmousedown = mousedown;
document.onmousemove = movemouse;
document.onmouseup = mouseup;
var lastobj; // Last draggable object we hovered over
var isdrag; // True if dragging an object
// This prevents browsers from highlighting the draggable text
// when you click on it. The table containing all the draggable
// text has id drag_drop.
window.onload = function()
...{
var e = document.getElementById(‘drag_drop‘);
if (e) ...{
if (moz)
e.onmousedown = function () ...{ return false; } // mozilla
else
e.onselectstart = function () ...{ return false; } // ie
}
}
// Checks to see if a swap is allowed between two objects based on their ids.
// Change this as you see fit to permit or forbid swapping each possible pair
// of draggable items.
function allowswap(a,b)
...{
if (a.id == "dragdropa" && b.id == "dragdropb" || a.id == "dragdropb" && b.id == "dragdropa")
return true;
return false;
}
// Returns true if an object is draggable - change this to suit your needs.
function isdraggable(obj)
...{
if (obj.id.substr(0,8) == "dragdrop")
return true;
return false;
}
// Callback when mouse button is pressed. This checks if an item is draggable, and
// if so initiates the process.
function mousedown(e) 
...{
var obj = moz ? e.target : event.srcElement;
// Trace up DOM tree to see if item clicked on is draggable. This allows
// for the fact that you may click, for example, on a TD while the enclosing
// TR is the draggable object.
while (obj.tagName != "HTML" && obj.tagName != "BODY" && !isdraggable(obj)) ...{
obj = moz ? obj.parentNode : obj.parentElement;
}
if (isdraggable(obj)) ...{
// If draggable, set a global flag to track this, and save a pointer
// to the object in a global variable as well (dragobj).
isdrag = true;
dragobj = obj;
// origx, origy is original starting location of dragged object
origx = dragobj.style.left;
origy = dragobj.style.top;
// x,y is absolute co-ordinates within the window
x = moz ? e.clientX : event.clientX;
y = moz ? e.clientY : event.clientY;
// While offsetX, offSetY depend on where exactly you clicked on the object.
// Thus if you click in the middle of the object, it will be ‘attached‘ to
// the mouse at that point, and not the upper left corner, for example.
offsetX = moz ? e.layerX + 2: event.x + 2;
offsetY = moz ? e.layerY + 2: event.y + 2;
}
}
// Callback when mouse is moved. It will change the cursor when you move over an object
// you can - or cannot - swap with.
function movemouse(e)
...{
// Check if we are dragging an object
if (isdrag) ...{
// If so, set the dragged object‘s position relative to how much the mouse has moved
// since first clicked.
dragobj.style.left = moz ? origx + e.clientX - x + offsetX + ‘px‘ : origx + event.clientX - x + offsetX;
dragobj.style.top = moz ? origy + e.clientY - y + offsetY + ‘px‘ : origy + event.clientY - y + offsetY;
var obj = moz ? e.target : event.srcElement;
// If we are over an element that we cannot swap with, change its cursor style
// to show that a swap is forbidden
if (obj != dragobj && isdraggable(obj) && !allowswap(dragobj,obj)) ...{
obj.style.cursor = ‘wait‘;
// save in a handle to the object in a global so we can reset the cursor later
lastobj = obj;
}
else if (lastobj) // reset the cursor as soon as we move off a non-swappable object
lastobj.style.cursor = ‘pointer‘;
return false;
}
else ...{
// Sometimes can get stuck with no drop icon, so restore cursor just to be safe,
// when not dragging but passing over a draggable item
var obj = moz ? e.target : event.srcElement;
if (isdraggable(obj))
obj.style.cursor = ‘pointer‘;
}
}
// Callback when mouse is released - checks if a swap should occur and
// returns dragged object to its starting position if not.
function mouseup(e)
...{
if (isdrag) ...{ // If something is being dragged
// Get the object over which the mouse button was just released
var obj = moz ? e.target : event.srcElement;
// Check if mouse was release over an object we can swap with
if (obj != dragobj && isdraggable(obj) && allowswap(dragobj, obj)) ...{
// A swap is allowed - swap color, tooltip and contents of the
// dragged object with that it was released over
var htm = obj.innerHTML;
obj.innerHTML = dragobj.innerHTML;
dragobj.innerHTML = htm;
var col = obj.style.color;
obj.style.color = dragobj.style.color;
dragobj.style.color = col;
var titl = obj.title;
obj.title = dragobj.title;
dragobj.title = titl;
// Set the position of the object we were dragging (dragobj) where the
// other object (obj) is located and move obj to the original location
// of dragobj before it was dragged (origx, origy).
dragobj.style.left = obj.style.left;
dragobj.style.top = obj.style.top;
obj.style.left = origx;
obj.style.top = origy;
}
else ...{
// No swap can occur so return dragged object to its starting position
dragobj.style.left = origx;
dragobj.style.top = origy;
}
// Restore cursor to pointer if it was changed in movemouse above
if (lastobj) ...{
lastobj.style.cursor = ‘pointer‘;
}
}
isdrag = false; // Nothing is being dragged now
}
<table id="drag_drop" align="center" style="font-size:150%; color:green; background-color:#88ccff; white-space: nowrap;">
<tr>
<td>
<span id="dragdropa" style="cursor: pointer; position: relative; color: #ff0000" title="John Doe">John</span>
</td>
</tr>
<tr>
<td>
<span id="dragdropb" style="cursor: pointer; position: relative; color: #a0522d" title="Jane Smith">Jane</span>
</td>
</tr>
<tr>
<td>
<span id="dragdropc" style="cursor: pointer; position: relative; color: #00aa00" title="Bill Schwartz">Bill</span>
</td>
</tr>
</table>标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/4279693.html