2016-03-04 87 views
-5

当鼠标悬停在图层上时,我希望图像变暗一点(Overlay?)。然后,当鼠标悬停时,图片中的按钮应该出现,如果鼠标悬停在一个按钮上,它应该变成红色(如图片),并且图像描述文本应该出现在按钮下方(如图片),然后if一个按钮被点击它应该带我们到一个新的URL(说,如果按钮被点击,它将我们带到www.google.com),任何人都可以提供任何代码?我不知道该怎么做。在鼠标悬停和图像变暗时在图片上插入按钮

enter image description here

+0

如果你不知道该怎么做,你的第一个问题是你不懂HTML,CSS或JavaScript。为了解决这个问题,你首先需要学习。在互联网上有很多教程,使用您选择的搜索引擎找到一个并开始。我们不是一个免费的编码服务,我们只是在这里帮助您解决您的编程问题(一旦您已经付出努力并且能够清楚地传达您在实施自己的解决方案时面临的问题)。顺便说一句,你已经成为这个网站的成员8个月,问了14个问题,仍然不知道网站的规则? –

+1

欢迎来到SO。请访问[帮助],看看有什么和如何问。提示:不是elance.com – mplungjan

+1

从这些(http://tympanus.net/Tutorials/CaptionHoverEffects)学习并自己尝试,如果仍然卡住粘贴代码,我们将帮助您使用它 –

回答

2

我觉得这是你want.try这算什么。我只关心你的主要观点。这将对你有用。

<!DOCTYPE html> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head> 
 
<title>Test</title> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> 
 
</head> 
 
<style type="text/css"> 
 
body{ 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
div.contain{ 
 
    width: 1000px; 
 
    height: 667px; 
 
    border: 2px solid black; 
 
    margin: 100px; 
 
    margin-top: 10px; 
 
    background-image: url(https://dancingaspen.files.wordpress.com/2015/09/coffee-shop-mug.jpg); 
 
} 
 

 
div.mask{ 
 
    width: 100%; 
 
    height: 100%; 
 
    background-color: black; 
 
    position:relative; 
 
    opacity: 0; 
 

 
} 
 

 
.zoom{ 
 
    width: 150px; 
 
    height: 50px; 
 
    color: white; 
 
    font-size: 35px; 
 
    background-color: red; 
 
    position: absolute; 
 
    top: 300px; 
 
    left: 300px; 
 
    border: 2px solid white; 
 
    border-radius: 10px; 
 
    display: none; 
 
    text-align: center; 
 
    font-size: monospace; 
 
    padding-top: 15px; 
 
    text-decoration: none; 
 
} 
 

 
.description{ 
 
    
 
    position: absolute; 
 
    width: 70%; 
 
    height: 30%; 
 
    top:410px; 
 
    left: 12%; 
 
    font-size: 35px; 
 
    color: white; 
 
    font-family: zapfino; 
 
    text-align: center; 
 
    display: none; 
 
} 
 

 

 
</style> 
 
<body> 
 

 
<div class="contain"> 
 
<div class="mask"></div> 
 
    <a href="#" target="_blank" class="zoom">ZOOM</a> 
 
    <div class="description">your description here</div> 
 
</div> 
 

 
<script type="text/javascript"> 
 
    $(document).ready(function(){ 
 
    $(".contain").mouseenter(function(){ 
 
     $(".mask").animate({opacity:0.5},1000); 
 
     $(".zoom").fadeIn(1500); 
 
     $(".description").fadeIn(1500); 
 
    }); 
 

 
    $(".contain").mouseleave(function(){ 
 
     $(".mask").animate({opacity:0},1000); 
 
     $(".zoom").fadeOut(); 
 
     $(".description").fadeOut(); 
 
    }); 
 
    }); 
 
</script> 
 

 
</body> 
 
</html>

只需复制,粘贴和运行。

0

使用'悬停'设置可以使用直线css完成变暗图像。 选择你的照片(或最好是包含图像的div)并设置div:将光标悬停在较低的不透明度上,如不透明度:0.5;

如果你想使图像变暗,而无需一个黑暗的背景,你可以设置图像作为div的背景 enter code here enter code here

enter code here .parent {背景:“图像/ image.jpg的”;} enter code here .child {background-color:black; opacity:0;} enter code here .child:hover {opacity:0.7;}

相关问题