Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/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
Html 使用CSS将onclick链接事件添加到图像_Html_Css_Onclick - Fatal编程技术网

Html 使用CSS将onclick链接事件添加到图像

Html 使用CSS将onclick链接事件添加到图像,html,css,onclick,Html,Css,Onclick,我有一个在悬停时反弹的图像,但我希望用户也能够单击该图像 并被带到另一个网站。我需要在代码中更改什么才能使其工作 .my-custom-control { background: url('my-image.png'); background-size: 150px 150px; background-repeat: no-repeat; background-position: center; background-clip: border-box; transition: backgrou

我有一个在悬停时反弹的图像,但我希望用户也能够单击该图像 并被带到另一个网站。我需要在代码中更改什么才能使其工作

.my-custom-control { background: url('my-image.png'); 
background-size: 150px 150px;
background-repeat: no-repeat;
background-position: center;
background-clip: border-box;
transition: background-size 0.2s;
-webkit-transition: background-size 0.2s;
transition-timing-function: cubic-bezier(.05,1.2,.72,1.2);
display: inline-block; 
width: 200px; 
height: 200px; 
}
.my-custom-control:hover {
    background-size: 200px;
}

将图像包装到锚定标记中

<a href="http://www.yahoo.com"><img src="" class="my-custom-control"></a>


您也可以显示HTML吗。如果您有JavaScript,也可以使用JavaScript。用
包装
,并将动画应用于该元素,而不是
。此处的完整代码:很好,现在请在您的问题中添加相关的最小代码;不要指望我们为了帮助你的特权而访问外部网站。我们很乐意提供帮助,但您的工作是让我们尽可能容易地提供帮助。对不起,我以为您需要完整的代码。还以为你回答问题会得到代表分数。你有一个我没有一个刚刚看到你的代码。。可以使用var imageLink=document.createElement('a')在代码中创建锚元素;然后添加你的图像(我相信在你的例子中它是一个div,如:imageLink.appendChild().Awesome。你能更具体一点吗?我不知道把var-imageLink放在哪里以及如何使用它。下面是你想要在你共享的文件中更改的代码….var-imageLink=document.createElement('a'));imageLink.href='';var container=L.DomUtil.create('div','my custom control');imageLink.appendChild(container);/…初始化其他DOM元素,添加侦听器等。返回imageLink;