Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将div隐藏在blackness下,悬停时用渐变圆显示下面的项目_Javascript_Svg_Canvas_Html5 Canvas_Dom Events - Fatal编程技术网

Javascript 将div隐藏在blackness下,悬停时用渐变圆显示下面的项目

Javascript 将div隐藏在blackness下,悬停时用渐变圆显示下面的项目,javascript,svg,canvas,html5-canvas,dom-events,Javascript,Svg,Canvas,Html5 Canvas,Dom Events,我的想法是,你只能在网站上看到黑色,但当你用鼠标悬停在网站上时,它会显示一个径向渐变的白色圆圈,显示它下面的菜单项,如“联系人”、“信息”和“产品”。当你点击“产品”时,页面上的所有项目都会出现,但它们仍然隐藏在黑色下,只有当你将鼠标悬停在页面上时才会显示出来。如果您单击任何产品,您可以通过标记链接进入产品页面 所以我得到了两个部分——1)用渐变圆显示东西,2)点击“产品”后显示的产品——来工作,但是当产品出现时,带有渐变的画布部分就卡住了。这可能是因为我试图通过分离这两个交互来以一种不太正常的

我的想法是,你只能在网站上看到黑色,但当你用鼠标悬停在网站上时,它会显示一个径向渐变的白色圆圈,显示它下面的菜单项,如“联系人”、“信息”和“产品”。当你点击“产品”时,页面上的所有项目都会出现,但它们仍然隐藏在黑色下,只有当你将鼠标悬停在页面上时才会显示出来。如果您单击任何产品,您可以通过标记链接进入产品页面

所以我得到了两个部分——1)用渐变圆显示东西,2)点击“产品”后显示的产品——来工作,但是当产品出现时,带有渐变的画布部分就卡住了。这可能是因为我试图通过分离这两个交互来以一种不太正常的方式进行,如下所示:

<!DOCTYPE HTML>
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="./assets/stylesheet/normalize.css">
    <link rel="stylesheet" type="text/css" href="./assets/stylesheet/style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
  </head>
  <body>
    <div id="menu">
      <div class="menu-item" id="products"><a>Products</a></div>
      <div class="menu-item" id="contact"><a href="./contact.html">News</a></div>
    </div>
    <script>
      // create a full screen canvas
      var canvas = document.createElement("canvas");
      canvas.style.position = "absolute";
      canvas.style.left     = "0px";
      canvas.style.top      = "0px";
      canvas.style.zIndex   = 10;
      canvas.width          = window.innerWidth;
      canvas.height         = window.innerHeight;
      document.body.appendChild(canvas);
      // var to hold context
      var ctx;

      // load an image
      var image = new Image();
      image.src = "./assets/images/white.jpg";

      // add resize event
      var resize = function(){
          canvas.width   = window.innerWidth;
          canvas.height  = window.innerHeight;
          ctx            = canvas.getContext("2d");
      }
      // add mouse event. Because it is full screen no need to bother with offsets
      var mouse = function(event){
          posX = event.clientX;
          posY = event.clientY;
      }
      // incase the canvas size is changed
      window.addEventListener("resize",resize);

      // listen to the mouse move
      canvas.addEventListener("mousemove",mouse);

      // Call resize as that gets our context
      resize();

      // define the gradient
      var cirRadius = 300;

      var posX = 100; // this will be set by the mouse
      var posY = 100;
      var RGB = [11,11,11] ; // black any values from 0 to 255
      // var alphas = [0,0,0.2,0.5,0.9,0.95,1]; // zero is transparent one is not
      var alphas = [0,0,0.1,0.5,1];

      // the update function
      var update = function(){
          if(ctx){  // make sure all is in order..
              if(image.complete){ // draw the image when it is ready
                  ctx.drawImage(image,0,0,canvas.width,canvas.height)
              }else{ // while waiting for image clear the canvas
                  ctx.clearRect(0,0,canvas.width,canvas.height);
              }
              // create gradient
              var grad = ctx.createRadialGradient(posX,posY,0,posX,posY,cirRadius);
              // add colour stops
              var len = alphas.length-1;
              alphas.forEach((a,i) => {
                   grad.addColorStop(i/len,`rgba(${RGB[0]},${RGB[1]},${RGB[2]},${a})`);
              });
              // set fill style to gradient
              ctx.fillStyle = grad;
              // render that gradient
              ctx.fillRect(0,0,canvas.width,canvas.height);
          }
          requestAnimationFrame(update); // keep doing it till cows come home.

      }

      // start it all happening;
      requestAnimationFrame(update);

    </script>

    <script>
      $("#products").click(function(){

        $("#products").remove();

        var diagram = document.createElement("div");
        diagram.style.position = "absolute";
        diagram.style.left = "0px";
        diagram.style.top = "0px"
        diagram.style.zIndex  = 100;
        diagram.style.width = window.innerWidth + "px";
        diagram.style.height = window.innerHeight + "px";
        document.body.appendChild(diagram);

        var products = [{
                      titleShort: "Black",
                      mainImage: "N/A",
                      link: "./black.html"
                    }, {
                      titleShort: "White",
                      mainImage: "N/A",
                      link: "./white.html"
                    }, {
                      titleShort: "Red",
                      mainImage: "N/A",
                      link: "./red.html"
                    }, {
                      titleShort: "Blue",
                      mainImage: "N/A",
                      link: "./blue.html"
                    }]

        for (var i = 0; i < products.length; i++) {
          var product = document.createElement("div");
          diagram.appendChild(product);
          productstyle.position = "absolute";
          product.style.width = "120px";
          product.style.height = "50px";
          product.style.top = i * 100 + "px";
          product.style.left = i * 100 + "px";
          product.style.textAlign = "center";
          var circle = document.createElement("a");
          circle.style.width = "15px";
          circle.style.height = "15px";
          circle.style.borderRadius = "50%";
          circle.style.backgroundColor = "black";
          circle.style.marginLeft = "auto";
          circle.style.marginRight = "auto";
          circle.href = products[i].link;
          product.appendChild(circle);
        }

      });

    </script>

  </body>
</html>

//创建全屏画布
var canvas=document.createElement(“canvas”);
canvas.style.position=“绝对”;
canvas.style.left=“0px”;
canvas.style.top=“0px”;
canvas.style.zIndex=10;
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
document.body.appendChild(画布);
//保存上下文的var
var-ctx;
//加载图像
var image=新图像();
image.src=“./assets/images/white.jpg”;
//添加调整大小事件
var resize=function(){
canvas.width=window.innerWidth;
canvas.height=window.innerHeight;
ctx=canvas.getContext(“2d”);
}
//添加鼠标事件。因为它是全屏的,所以不需要担心偏移量
变量鼠标=函数(事件){
posX=event.clientX;
posY=event.clientY;
}
//如果画布大小已更改
addEventListener(“调整大小”,调整大小);
//听鼠标移动
addEventListener(“mousemove”,鼠标);
//调用resize以获取上下文
调整大小();
//定义渐变
半径=300;
var posX=100;//这将由鼠标设置
var-posY=100;
变量RGB=[11,11,11];//黑色:0到255之间的任何值
//阿尔法变量=[0,0,0.2,0.5,0.9,0.95,1];//零是透明的,而一不是透明的
阿尔法风险值=[0,0,0.1,0.5,1];
//更新功能
var update=函数(){
如果(ctx){//请确保一切正常。。
如果(image.complete){//在图像准备就绪时绘制图像
drawImage(图像,0,0,canvas.width,canvas.height)
}否则{//在等待图像时清除画布
clearRect(0,0,canvas.width,canvas.height);
}
//创建渐变
var grad=ctx.createRadialGradient(posX,posY,0,posX,posY,ciradius);
//添加颜色停止
var len=字母长度-1;
alphas.forEach((a,i)=>{
grad.addColorStop(i/len,`rgba(${RGB[0]},${RGB[1]},${RGB[2]},${a})`);
});
//将填充样式设置为渐变
ctx.fillStyle=梯度;
//渲染该渐变
ctx.fillRect(0,0,canvas.width,canvas.height);
}
requestAnimationFrame(更新);//继续这样做直到奶牛回家。
}
//开始这一切的发生;
requestAnimationFrame(更新);
$(“#产品”)。单击(函数(){
$(“#产品”).remove();
var图=document.createElement(“div”);
diagram.style.position=“绝对”;
diagram.style.left=“0px”;
diagram.style.top=“0px”
diagram.style.zIndex=100;
diagram.style.width=window.innerWidth+“px”;
diagram.style.height=window.innerHeight+“px”;
文件.正文.附件(图);
var乘积=[{
标题短:“黑色”,
主图像:“不适用”,
链接:“./black.html”
}, {
标题短:“白色”,
主图像:“不适用”,
链接:“./white.html”
}, {
标题短:“红色”,
主图像:“不适用”,
链接:“./red.html”
}, {
标题短:“蓝色”,
主图像:“不适用”,
链接:“./blue.html”
}]
对于(变量i=0;i
注:为方便起见,所有产品仅用点/圆表示

如果我将两个部分合并到一个画布中,可能是最好的。例如,现在我们将白色图像作为画布的背景,如果我们可以通过某种方式使用产品更新图像?但我对canvas非常陌生,因此不知道如何做到这一点。欢迎您提出任何其他建议。

您可以使用无显示的div(a),边框半径为50%,边框值高得离谱(实心、黑色),位置固定,z索引高。然后使用宽度为100%的第二个div(b),