前端滑动验证+拼图滑动验证效果

相信大家都玩过B站,B站在登陆的时候有个拼图滑动验证,今天就整合一下前端实现的滑动验证

拖动滑动验证(无背景图片)

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>拖动滑块验证</title>
</head>
<body>
  <meta charset="utf8">
    <style>
        /* 滑动控件容器,灰色背景 */
        #dragContainer {
            position: relative;
            display: inline-block;
            background: #e8e8e8;
            width: 300px;
            height: 33px;
            border: 2px solid #e8e8e8;
        }
        /* 滑块左边部分,绿色背景 */
        #dragBg {
            position: absolute;
            background-color: #7ac23c;
            width: 0px;
            height: 100%;
        }
        /* 滑动验证容器文本 */
        #dragText {
            position: absolute;
            width: 100%;
            height: 100%;
            /* 文字水平居中 */
            text-align: center;
            /* 文字垂直居中,这里不能用百分比,因为百分比是相对原始line-height的,而非div高度 */
            line-height: 33px;
            /* 文本不允许选中 */
            user-select: none;
            -webkit-user-select: none;
        }
        /* 滑块 */
        #dragHandler {
            position: absolute;
            width: 40px;
            height: 100%;
            cursor: move;
        }
        /* 滑块初始背景 */
        .dragHandlerBg {
            background: #fff no-repeat center url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo0ZDhlNWY5My05NmI0LTRlNWQtOGFjYi03ZTY4OGYyMTU2ZTYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NTEyNTVEMURGMkVFMTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NTEyNTVEMUNGMkVFMTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTQgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo2MTc5NzNmZS02OTQxLTQyOTYtYTIwNi02NDI2YTNkOWU5YmUiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NGQ4ZTVmOTMtOTZiNC00ZTVkLThhY2ItN2U2ODhmMjE1NmU2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+YiRG4AAAALFJREFUeNpi/P//PwMlgImBQkA9A+bOnfsIiBOxKcInh+yCaCDuByoswaIOpxwjciACFegBqZ1AvBSIS5OTk/8TkmNEjwWgQiUgtQuIjwAxUF3yX3xyGIEIFLwHpKyAWB+I1xGSwxULIGf9A7mQkBwTlhBXAFLHgPgqEAcTkmNCU6AL9d8WII4HOvk3ITkWJAXWUMlOoGQHmsE45ViQ2KuBuASoYC4Wf+OUYxz6mQkgwAAN9mIrUReCXgAAAABJRU5ErkJggg==");
        }
        /* 验证成功时的滑块背景 有√*/
        .dragHandlerOkBg {
            background: #fff no-repeat center url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo0ZDhlNWY5My05NmI0LTRlNWQtOGFjYi03ZTY4OGYyMTU2ZTYiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6NDlBRDI3NjVGMkQ2MTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6NDlBRDI3NjRGMkQ2MTFFNEI5NDBCMjQ2M0ExMDQ1OUYiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENDIDIwMTQgKE1hY2ludG9zaCkiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDphNWEzMWNhMC1hYmViLTQxNWEtYTEwZS04Y2U5NzRlN2Q4YTEiIHN0UmVmOmRvY3VtZW50SUQ9InhtcC5kaWQ6NGQ4ZTVmOTMtOTZiNC00ZTVkLThhY2ItN2U2ODhmMjE1NmU2Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+k+sHwwAAASZJREFUeNpi/P//PwMyKD8uZw+kUoDYEYgloMIvgHg/EM/ptHx0EFk9I8wAoEZ+IDUPiIMY8IN1QJwENOgj3ACo5gNAbMBAHLgAxA4gQ5igAnNJ0MwAVTsX7IKyY7L2UNuJAf+AmAmJ78AEDTBiwGYg5gbifCSxFCZoaBMCy4A4GOjnH0D6DpK4IxNSVIHAfSDOAeLraJrjgJp/AwPbHMhejiQnwYRmUzNQ4VQgDQqXK0ia/0I17wJiPmQNTNBEAgMlQIWiQA2vgWw7QppBekGxsAjIiEUSBNnsBDWEAY9mEFgMMgBk00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==");
        }
    </style>
    <script>
       //加载(事件会在页面加载完成后触发)
        window.onload = function() {
            //获取滑动控件容器,灰色背景
            var dragContainer = document.getElementById("dragContainer");
            //获取滑块左边部分,绿色背景
            var dragBg = document.getElementById("dragBg");
            //获取滑动验证容器文本
            var dragText = document.getElementById("dragText");
            //获取滑块
            var dragHandler = document.getElementById("dragHandler");

            //滑块的最大偏移量                 =     滑动验证容器文本长度                  -      滑块长度
            var maxHandlerOffset = dragContainer.clientWidth - dragHandler.clientWidth;
            //是否验证成功的标记
            var isVertifySucc = false;

            initDrag();

            function initDrag() {
                //在滑动验证容器文本写入“拖动滑块验证”
                dragText.textContent = "拖动滑块验证";
                //给滑块添加鼠标按下监听
                dragHandler.addEventListener("mousedown", onDragHandlerMouseDown);
            }

           //选中滑块
            function onDragHandlerMouseDown() {
                //鼠标移动监听
                document.addEventListener("mousemove", onDragHandlerMouseMove);
                //鼠标松开监听
                document.addEventListener("mouseup",  onDragHandlerMouseUp);
            }

           //滑块移动
            function onDragHandlerMouseMove() {
                /*
                html元素不存在width属性,只有clientWidth
                offsetX是相对当前元素的,clientX和pageX是相对其父元素的
                */
               //滑块移动量
                var left = event.clientX - dragHandler.clientWidth / 2;
                //
                if(left < 0) {
                    left = 0;
                 //如果滑块移动量   > 滑块的最大偏移量 ,则调用验证成功函数
                } else if(left > maxHandlerOffset) {
                    left = maxHandlerOffset;
                    verifySucc();
                }
                //滑块移动量
                dragHandler.style.left = left + "px";
                //绿色背景的长度
                dragBg.style.width = dragHandler.style.left;
            }

           //松开滑块函数
            function onDragHandlerMouseUp() {
                //移除鼠标移动监听
                document.removeEventListener("mousemove", onDragHandlerMouseMove);
                //移除鼠标松开监听
                document.removeEventListener("mouseup", onDragHandlerMouseUp);
                //初始化滑块移动量
                dragHandler.style.left = 0;
                //初始化绿色背景
                dragBg.style.width = 0;
            }

            //验证成功
            function verifySucc() {
                //成功标记,不可回弹
                isVertifySucc = false;
                //容器文本的文字改为白色“验证通过”字体
                dragText.textContent = "验证通过";
                dragText.style.color = "white";
                //验证通过的滑块背景
                dragHandler.setAttribute("class", "dragHandlerOkBg");
                //移除鼠标按下监听
                dragHandler.removeEventListener("mousedown", onDragHandlerMouseDown);
                //移除 鼠标移动监听
                document.removeEventListener("mousemove", onDragHandlerMouseMove);
                //移除鼠标松开监听
                document.removeEventListener("mouseup", onDragHandlerMouseUp);
                // 匹配成功以后写入你要跳转的页面
                window.location.href="成功页面.html";
            };
        }
    </script>
</head>
<body>
    <div id="dragContainer"><!-- 容器初始背景 -->
        <div id="dragBg"></div><!-- 绿色背景 -->
        <div id="dragText"></div><!-- 滑动容器文本 -->
        <div id="dragHandler" class="dragHandlerBg"></div>
    </div> <!--    滑块         滑块初始背景 -->
</body>
</html>

效果图:

图片滑动验证

css

.block {
  position: absolute;
  left: 0;
  top: 0;
}

.sliderContainer {
  position: relative;
  text-align: center;
  width: 310px;
  height: 40px;
  line-height: 40px;
  margin-top: 15px;
  background: #f7f9fa;
  color: #45494c;
  border: 1px solid #e4e7eb;
}

.sliderContainer_active .slider {
  height: 38px;
  top: -1px;
  border: 1px solid #1991FA;
}

.sliderContainer_active .sliderMask {
  height: 38px;
  border-width: 1px;
}

.sliderContainer_success .slider {
  height: 38px;
  top: -1px;
  border: 1px solid #52CCBA;
  background-color: #52CCBA !important;
}

.sliderContainer_success .sliderMask {
  height: 38px;
  border: 1px solid #52CCBA;
  background-color: #D2F4EF;
}

.sliderContainer_success .sliderIcon {
  background-position: 0 0 !important;
}

.sliderContainer_fail .slider {
  height: 38px;
  top: -1px;
  border: 1px solid #f57a7a;
  background-color: #f57a7a !important;
}

.sliderContainer_fail .sliderMask {
  height: 38px;
  border: 1px solid #f57a7a;
  background-color: #fce1e1;
}

.sliderContainer_fail .sliderIcon {
  top: 14px;
  background-position: 0 -82px !important;
}
.sliderContainer_active .sliderText, .sliderContainer_success .sliderText, .sliderContainer_fail .sliderText {
  display: none;
}

.sliderMask {
  position: absolute;
  left: 0;
  top: 0;
  height: 40px;
  border: 0 solid #1991FA;
  background: #D1E9FE;
}

.slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 40px;
  height: 40px;
  background: #fff;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: background .2s linear;
}

.slider:hover {
  background: #1991FA;
}

.slider:hover .sliderIcon {
  background-position: 0 -13px;
}

.sliderIcon {
  position: absolute;
  top: 15px;
  left: 13px;
  width: 14px;
  height: 12px;
  background: url(http://cstaticdun.126.net//2.6.3/images/icon_light.f13cff3.png) 0 -26px;
  background-size: 34px 471px;
}

.refreshIcon {
  position: absolute;
  right: 0;
  top: 0;
  width: 34px;
  height: 34px;
  cursor: pointer;
  background: url(http://cstaticdun.126.net//2.6.3/images/icon_light.f13cff3.png) 0 -437px;
  background-size: 34px 471px;
}

js

(function (window) {
  const l = 42, // 滑块边长
    r = 9, // 滑块半径
    w = 310, // canvas宽度
    h = 155, // canvas高度
    PI = Math.PI
  const L = l + r * 2 + 3 // 滑块实际边长

  function getRandomNumberByRange (start, end) {
    return Math.round(Math.random() * (end - start) + start)
  }

  function createCanvas (width, height) {
    const canvas = createElement(‘canvas‘)
    canvas.width = width
    canvas.height = height
    return canvas
  }

  function createImg (onload) {
    const img = createElement(‘img‘)
    img.crossOrigin = "Anonymous"
    img.onload = onload
    img.onerror = () => {
      img.src = getRandomImg()
    }
    img.src = getRandomImg()
    return img
  }

  function createElement (tagName, className) {
    const elment = document.createElement(tagName)
    elment.className = className
    return elment
  }

  function addClass (tag, className) {
    tag.classList.add(className)
  }

  function removeClass (tag, className) {
    tag.classList.remove(className)
  }

  function getRandomImg () {
    return ‘https://picsum.photos/300/150/?image=‘ + getRandomNumberByRange(0, 1084)
  }

  function draw (ctx, x, y, operation) {
    ctx.beginPath()
    ctx.moveTo(x, y)
    ctx.arc(x + l / 2, y - r + 2, r, 0.72 * PI, 2.26 * PI)
    ctx.lineTo(x + l, y)
    ctx.arc(x + l + r - 2, y + l / 2, r, 1.21 * PI, 2.78 * PI)
    ctx.lineTo(x + l, y + l)
    ctx.lineTo(x, y + l)
    ctx.arc(x + r - 2, y + l / 2, r + 0.4, 2.76 * PI, 1.24 * PI, true)
    ctx.lineTo(x, y)
    ctx.lineWidth = 2
    ctx.fillStyle = ‘rgba(255, 255, 255, 0.7)‘
    ctx.strokeStyle = ‘rgba(255, 255, 255, 0.7)‘
    ctx.stroke()
    ctx[operation]()
    ctx.globalCompositeOperation = ‘overlay‘
  }

  function sum (x, y) {
    return x + y
  }

  function square (x) {
    return x * x
  }

  class jigsaw {
    constructor ({ el, onSuccess, onFail, onRefresh }) {
      el.style.position = el.style.position || ‘relative‘
      this.el = el
      this.onSuccess = onSuccess
      this.onFail = onFail
      this.onRefresh = onRefresh
    }

    init () {
      this.initDOM()
      this.initImg()
      this.bindEvents()
    }

    initDOM () {
      const canvas = createCanvas(w, h) // 画布
      const block = canvas.cloneNode(true) // 滑块
      const sliderContainer = createElement(‘div‘, ‘sliderContainer‘)
      const refreshIcon = createElement(‘div‘, ‘refreshIcon‘)
      const sliderMask = createElement(‘div‘, ‘sliderMask‘)
      const slider = createElement(‘div‘, ‘slider‘)
      const sliderIcon = createElement(‘span‘, ‘sliderIcon‘)
      const text = createElement(‘span‘, ‘sliderText‘)

      block.className = ‘block‘
      text.innerHTML = ‘向右滑动填充拼图‘

      const el = this.el
      el.appendChild(canvas)
      el.appendChild(refreshIcon)
      el.appendChild(block)
      slider.appendChild(sliderIcon)
      sliderMask.appendChild(slider)
      sliderContainer.appendChild(sliderMask)
      sliderContainer.appendChild(text)
      el.appendChild(sliderContainer)

      Object.assign(this, {
        canvas,
        block,
        sliderContainer,
        refreshIcon,
        slider,
        sliderMask,
        sliderIcon,
        text,
        canvasCtx: canvas.getContext(‘2d‘),
        blockCtx: block.getContext(‘2d‘)
      })
    }

    initImg () {
      const img = createImg(() => {
        this.draw()
        this.canvasCtx.drawImage(img, 0, 0, w, h)
        this.blockCtx.drawImage(img, 0, 0, w, h)
        const y = this.y - r * 2 - 1
        const ImageData = this.blockCtx.getImageData(this.x - 3, y, L, L)
        this.block.width = L
        this.blockCtx.putImageData(ImageData, 0, y)
      })
      this.img = img
    }

    draw () {
      // 随机创建滑块的位置
      this.x = getRandomNumberByRange(L + 10, w - (L + 10))
      this.y = getRandomNumberByRange(10 + r * 2, h - (L + 10))
      draw(this.canvasCtx, this.x, this.y, ‘fill‘)
      draw(this.blockCtx, this.x, this.y, ‘clip‘)
    }

    clean () {
      this.canvasCtx.clearRect(0, 0, w, h)
      this.blockCtx.clearRect(0, 0, w, h)
      this.block.width = w
    }

    bindEvents () {
      this.el.onselectstart = () => false
      this.refreshIcon.onclick = () => {
        this.reset()
        typeof this.onRefresh === ‘function‘ && this.onRefresh()
      }

      let originX, originY, trail = [], isMouseDown = false

      const handleDragStart = function (e) {
        originX = e.clientX || e.touches[0].clientX
        originY = e.clientY || e.touches[0].clientY
        isMouseDown = true
      }

      const handleDragMove = (e) => {
        if (!isMouseDown) return false
        const eventX = e.clientX || e.touches[0].clientX
        const eventY = e.clientY || e.touches[0].clientY
        const moveX = eventX - originX
        const moveY = eventY - originY
        if (moveX < 0 || moveX + 38 >= w) return false
        this.slider.style.left = moveX + ‘px‘
        const blockLeft = (w - 40 - 20) / (w - 40) * moveX
        this.block.style.left = blockLeft + ‘px‘

        addClass(this.sliderContainer, ‘sliderContainer_active‘)
        this.sliderMask.style.width = moveX + ‘px‘
        trail.push(moveY)
      }

      const handleDragEnd = (e) => {
        if (!isMouseDown) return false
        isMouseDown = false
        const eventX = e.clientX || e.changedTouches[0].clientX
        if (eventX == originX) return false
        removeClass(this.sliderContainer, ‘sliderContainer_active‘)
        this.trail = trail
        const { spliced, verified } = this.verify()
        if (spliced) {
          if (verified) {
            addClass(this.sliderContainer, ‘sliderContainer_success‘)
            typeof this.onSuccess === ‘function‘ && this.onSuccess()
          } else {
            addClass(this.sliderContainer, ‘sliderContainer_fail‘)
            this.text.innerHTML = ‘再试一次‘
            this.reset()
          }
        } else {
          addClass(this.sliderContainer, ‘sliderContainer_fail‘)
          typeof this.onFail === ‘function‘ && this.onFail()
          setTimeout(() => {
            this.reset()
          }, 1000)
        }
      }
      this.slider.addEventListener(‘mousedown‘, handleDragStart)
      this.slider.addEventListener(‘touchstart‘, handleDragStart)
      document.addEventListener(‘mousemove‘, handleDragMove)
      document.addEventListener(‘touchmove‘, handleDragMove)
      document.addEventListener(‘mouseup‘, handleDragEnd)
      document.addEventListener(‘touchend‘, handleDragEnd)
    }

    verify () {
      const arr = this.trail // 拖动时y轴的移动距离
      const average = arr.reduce(sum) / arr.length
      const deviations = arr.map(x => x - average)
      const stddev = Math.sqrt(deviations.map(square).reduce(sum) / arr.length)
      const left = parseInt(this.block.style.left)
      return {
        spliced: Math.abs(left - this.x) < 10,
        verified: stddev !== 0, // 简单验证下拖动轨迹,为零时表示Y轴上下没有波动,可能非人为操作
      }
    }

    reset () {
      this.sliderContainer.className = ‘sliderContainer‘
      this.slider.style.left = 0
      this.block.style.left = 0
      this.sliderMask.style.width = 0
      this.clean()
      this.img.src = getRandomImg()
    }

  }

  window.jigsaw = {
    init: function (opts) {
      return new jigsaw(opts).init()
    }
  }
}(window))

引用页面:

<link rel="stylesheet" href="../css/hdyz.css">
<script src="../js/myyz.js"></script>
<div id="captcha"></div>
<script type="text/javascript">
  jigsaw.init({
    el: document.getElementById(‘captcha‘),
  })
</script>

效果图:

谢谢观看!

原文地址:https://www.cnblogs.com/huangting/p/11285131.html

时间: 2024-10-07 09:32:33

前端滑动验证+拼图滑动验证效果的相关文章

前端MVC学习总结——AngularJS验证、过滤器

前端MVC学习总结--AngularJS验证.过滤器 目录 一.验证 二.过滤器 2.1.内置过滤器 2.1.1.在模板中使用过滤器 2.1.2.在脚本中调用过滤函数 2.2.自定义过滤器 三.指令(directive) 3.1.支持AngularJS功能的指令 3.1.1.应用与模块(ng-app) 3.1.2.控制器(ng-Controller) 3.1.3.包含(ng-Include) 3.1.4.不绑定(ngNonBindable) 3.2.扩展表单元素的指令 3.2.1.ng-opti

一种支持任意尺寸的图片滑动(上下左右滑动)效果

<! DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>任意尺寸的图片滑动</title> <style> div { margin: 0 auto; overflow: hidden;} .main { width: 100

8.3 应用滑动门技术的玻璃效果菜单

本例中要实现一个玻璃材质效果的水平菜单.为了表现出立体的视觉效果,以及玻璃的质感.必须借助图像才可以实现,完成后的效果如图1所示. 该实例文件位于网页学习网CSS教程资源的“第8章\03\glass-navi.htm”. 图1 玻璃效果的菜单 本例中用到了两个图像,分别作为整个菜单的背景色平铺使用的,和当鼠标指针经过某个菜单项的时候显示出来的. 从效果图中可以看出,玻璃材质图是一个固定的图像文件,而菜单中的各个菜单项宽窄不一,却都可以完整地显示出来,这是如何实现的呢?这里使用的就是“滑动门”技术

前端和后端的双重验证

ASP.NET MVC和WebForm 轻松实现前端和后端的双重验证 jquery.validate+ValidationSugar 上次不足的改进 可能上一个贴子给大家带来很多误解,所以我这次把DEMO完善了两个版本 [ASP.NET WEBFROM]和[ ASP.NET MVC] 修改了一些BUG,并且修改了一些细了 在上个贴子里有人说,看了response.write就全身不舒服,所以也就写了基于异步提交的例子 功能介绍 ValidationSugar.cs 负责后台验证和前端 form

自己动手写CPU之第六阶段(4)——验证移动操作指令实现效果

将陆续上传本人写的新书<自己动手写CPU>(尚未出版),今天是第23篇,我尽量每周四篇 6.4 测试程序 本节将通过一个测试程序验证为OpenMIPS处理器添加的移动操作指令是否实现正确,测试程序如下,对应本书附带光盘Code\Chapter6\AsmTest目录下的inst_rom.S文件. .org 0x0 .set noat .global _start _start: // 给寄存器$1.$2.$3.$4赋初值 lui $1,0x0000 # $1 = 0x00000000 lui $

前端与算法 leetcode 125. 验证回文串

目录 # 前端与算法 leetcode 125. 验证回文串 题目描述 概要 提示 解析 解法一:api侠 解法二:双指针 算法 传入测试用例的运行结果 执行结果 GitHub仓库 查看更多 # 前端与算法 leetcode 125. 验证回文串 题目描述 给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, a plan, a canal: Panama" 输出: tru

MVC验证03-自定义验证规则、禁止输入某些值

原文:MVC验证03-自定义验证规则.禁止输入某些值 本文继续体验自定义验证规则,需求是禁止输入某些值.本文与前2篇相关,请参考:MVC验证01-基础.远程验证   MVC验证02-自定义验证规则.邮件验证 自定义验证特性继承ValidationAttribute,并实现IClientValidatable接口 展开using System.ComponentModel.DataAnnotations; using System.Web.Mvc; namespace MvcValidation.

MVC验证04-自定义验证规则、日期范围验证

原文:MVC验证04-自定义验证规则.日期范围验证 本文体验范围验证.与本文相关的包括: MVC验证01-基础.远程验证   MVC验证02-自定义验证规则.邮件验证   MVC验证03-自定义验证规则.禁止输入某些值 当需要对字符串长度进行验证,可以用StringLength:[StringLength(100, ErrorMessage = "{0} 必须至少包含 {2} 个字符.", MinimumLength = 6)] 当需要对数组范围进行验证,可以用Range:[Range

MVC验证02-自定义验证规则、邮件验证

原文:MVC验证02-自定义验证规则.邮件验证 本文体验MVC自定义验证特性,来实现对邮件的验证.对于刚写完的自定义验证特性,起初只能支持后端验证.如果要让前端jquery支持,还必须对jquery的验证进行扩展. 本文与"MVC验证01-基础.远程验证"相关,如有需要,请参考. 当我们验证有关Email属性的时候,我们可能这样写: [RegularExpression(@"\w.+\@\w.+")] public string Email { get; set;