cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h1>Web Design</h1>
<p>These are the things you should know.</p>
<ol id="linklist">
	<li>
	  <a href="structure.html">Structure</a>
	</li>
	<li>
	  <a href="presentation.html">Presentation</a>
	</li>
	<li>
	  <a href="behavior.html">Behavior</a>
	</li>
</ol>	
            
          
!
            
              #slideshow {
  width: 100px;
  height: 100px;
  position: relative;
  overflow: hidden;
}
#preview {
  position: absolute;
}
            
          
!
            
              function addLoadEvent(func){
  var oldonload = window.onload;
  if(typeof window.onload != "function"){
    window.onload = func;
  }else{
    window.onload = function(){
      oldonload();
      func();
    }
  }
}

//把新元素插入到目标元素的后面
function insertAfter(newElement,targetElement){
  var parent = targetElement.parentNode;
  if(parent.lastChild == targetElement){
    parent.appendChild(newElement);
  }else{
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}


//移动元素
function moveElement(elementID,final_x,final_y,interval){
  if(!document.getElementById || !document.getElementById(elementID)) return false;
  
  var elem = document.getElementById(elementID);
  
  //如果elem已有movement属性,就把其复位
  if(elem.movement){
    clearTimeout(elem.movement);
  }
  if(!elem.style.left){
    elem.style.left = "0px";
  }
  if(!elem.style.top){
    elem.style.top = "0px";
  }
  
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  var dist = 0;//元素与目的地之间的距离
  
  if(xpos == final_x && ypos == final_y){
    return true;
  }if(xpos < final_x){
    dist = Math.ceil((final_x - xpos)/10);
    xpos += dist;
    // xpos++;
  }if(xpos > final_x){
    dist = Math.ceil((xpos - final_x)/10);
    xpos -= dist;
    // xpos--;
  }if(ypos < final_y){
    dist = Math.ceil((final_y - ypos)/10);
    ypos += dist;
    // ypos++;
  }if(ypos > final_y){
    dist = Math.ceil((ypos - final_y)/10);
    ypos -= dist;
    // ypos--;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+ elementID +"',"+ final_x +","+ final_y +","+ interval +")";
  elem.movement = setTimeout(repeat,interval);
}


//创建显示图片的div并给li添加鼠标滑过效果
function prepareSlideshow(){
  if(!document.getElementById || !document.getElementsByTagName || !document.getElementById("linklist")) return false;
  
  var slideshow = document.createElement("div");
  slideshow.setAttribute("id","slideshow");
  
  var img = document.createElement("img");
  img.setAttribute("src","http://images0.cnblogs.com/blog2015/386934/201506/231519409081111.gif");
  img.setAttribute("alt","building blocks of web design");
  img.setAttribute("id","preview");
   
  slideshow.appendChild(img);
  var linklist = document.getElementById("linklist");
  insertAfter(slideshow,linklist);
  
  var links = linklist.getElementsByTagName("a");
  links[0].onmouseover = function(){
    moveElement("preview",-100,0,10);
  }
  links[1].onmouseover = function(){
    moveElement("preview",-200,0,10);
  }
  links[2].onmouseover = function(){
    moveElement("preview",-300,0,10);
  }
}

addLoadEvent(prepareSlideshow);
            
          
!
999px
Loading ..................

Console