jquery - 使用 jquery 淡入淡出

标签 jquery html css

我想在将鼠标悬停在 a 标签上时打开一个 div。我可以用 css 来做到这一点,但我想对那个 div 应用淡入和淡出。我做不到。

<a href="#">
   <img src="img/detayaltresim1.jpg" alt="">
   <div></div>
</a>


div{
    position: absolute;
    width: 200px;
    height: 80px;
    background: #000;
    bottom: 46px;
    left: -78px;
    z-index: 2;
    display:block;
}
a{
    display: block;
    position: relative;
}
a:hover div {
    display:block;
}

我的 a 标签有父标签。我无法用 j-query 做到这一点。为什么?

<script>
            $('urundetayisagteknik2 a').mouseover(function(){
            //show the box
            $(this).children('.urundetayisagteknik2 a div').stop().animate({opacity:1},300);
            });

            $('urundetayisagteknik2 a').mouseleave(function(){
             //hide the box
            $(this).children('.urundetayisagteknik2 a div').stop().animate({opacity:0},500);
            });
</script>

最佳答案

你在 jquery 中的类名没有 . 可能是错误。 编辑如下:

$('.urundetayisagteknik2 a').mouseover(function(){
  //show the box
  $(this).children('.urundetayisagteknik2 a div').stop().animate({opacity:1},300);
});

或者您可以尝试以下方法

CSS

<style>
div{
    position: absolute;
    width: 200px;
    height: 80px;
    background: #000;
    top: 46px;
    left: 20px;
    z-index: 2;
    display:none;
}
a{
    display: block;
    position: relative;
}
</style>

HTML

<a class="link" href="#">
   Link
   <div></div>
</a>

JQuery

<script>
$('.link').mouseover(function(){
    $('.link div').fadeIn();
});

$('.link').mouseleave(function(){
    $('.link div').fadeOut();
});
</script>

关于jquery - 使用 jquery 淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21725672/

相关文章:

javascript - 在DOJO确认对话框中动态设置onExecute回调函数

javascript - 让元素在悬停时悬停,添加关闭按钮以便它记住cookie?

jquery - 将文本(纯文本)从tinymce复制到textarea

html - 使用 html5 和 css 构建注册表时出现以下错误。出现以下错误

javascript - 如何根据表格单元格存储的数据改变其背景?

html - margin 不起作用

javascript - 如何在 d3 多折线图中使用 json 数据而不是 tsv 文件?

javascript - 如何在PHP中的特定时间使用不同的变量

twitter-bootstrap - 如何在 Bootstrap 3 中删除 navbar-inverse 的 "border-radius"?

java - 如何在 GWT 中使用 HTML Component File(.htc) 来应用 CSS3?