文章作者

Chris Coyier

创始人、作家、设计师、垃圾邮件删除者、邮件个性

指向文章“切换文本”的直接链接

切换文本

假设你有一个链接可以显示更多选项,这些选项会扩展选项列表。它显示为“更多选项”。使用 .toggle().slideToggle() 切换这些选项很容易,但文本保持不变。要切换文本……

指向文章“计算鼠标与元素之间的距离”的直接链接

计算鼠标与元素之间的距离

(function() {
    
    var mX, mY, distance,
        $distance = $('#distance span'),
        $element  = $('#element');

    function calculateDistance(elem, mouseX, mouseY) {
        return Math.floor(Math.sqrt(Math.pow(mouseX - (elem.offset().left+(elem.width()/2)), 2) + Math.pow(mouseY - (elem.offset().top+(elem.height()/2)), 2)));
    }

    $(document).mousemove(function(e) {  
        mX = e.pageX;
        mY = e.pageY;
        distance = calculateDistance($element, 
指向文章“带阴影的六边形”的直接链接

带阴影的六边形

<div class="hexagon"><span></span></div>
.hexagon {
  width: 100px;
  height: 55px;
  position: relative;
}

.hexagon, 
.hexagon:before, 
.hexagon:after {
  background: red;
  box-shadow: 0 0 10px rgba(0,0,0,0.8);   
}

.hexagon:before,
.hexagon:after {
  content: "";
  position: absolute;
  left: 22px;
  width: 57px;
  height: 57px;
  transform: rotate(145deg) skew(22.5deg);
}

指向文章“对角线格纸渐变”的直接链接

对角线格纸渐变

#example-gradient {
  height: 200px;
  margin: 0 0 20px 0;
  background-color: #eaeaea;
  background-size: 20px 20px;
  background-image:
     -webkit-repeating-linear-gradient(45deg, rgba(0, 191, 255, .5), rgba(0, 191, 255, .5) 1px, transparent 1px, transparent 15px),
     -webkit-repeating-linear-gradient(-45deg, rgba(255, 105, 180, .5), rgba(255, 105, 180, .5) 1px, transparent