Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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 淡入/淡出js鼠标悬停事件_Javascript_Jquery - Fatal编程技术网

Javascript 淡入/淡出js鼠标悬停事件

Javascript 淡入/淡出js鼠标悬停事件,javascript,jquery,Javascript,Jquery,我希望在我的页面上为菜单实现鼠标悬停事件- 我在左边有3个标题,在右边有一个相应的内容div,在那里会出现相关的文本 为了一个有效的js解决方案,我访问了所有论坛,我已经决定: 它使用一个非常简单的js函数: $("#products").tabs("div.description", {event:'mouseover'}); 然而,我希望做的是加入一个fadeIn(),fadeOut效果,这样当用户将鼠标悬停在页面左侧的标题上时,显示的现有内容将淡出,而相关内容将淡入查看 html编码是

我希望在我的页面上为菜单实现鼠标悬停事件-

我在左边有3个标题,在右边有一个相应的内容div,在那里会出现相关的文本

为了一个有效的js解决方案,我访问了所有论坛,我已经决定:

它使用一个非常简单的js函数:

$("#products").tabs("div.description", {event:'mouseover'});
然而,我希望做的是加入一个fadeIn(),fadeOut效果,这样当用户将鼠标悬停在页面左侧的标题上时,显示的现有内容将淡出,而相关内容将淡入查看

html编码是:

<div id="products" >

<img src="home.png" alt="home" />

<img src="services.png" alt="services" /> 

<img src="contact.png" alt="contact" /> 

</div>

<div class="description" id="home" >
 .. content .. 
</div>

<div class="description" id="services" >
 .. content .. 
</div>

<div class="description" id="contact" >
 .. content .. 
</div>

.. 内容。。
.. 内容。。
.. 内容。。
我曾试图在这个网站上加入线程5404775,但根本无法让它工作

非常感谢的任何帮助

这可能有用:

$("img", "#products").hover(function() {

    var id = $(this).attr("alt");
    $("#" + id).fadeIn("slow");

}, function() {

    var id = $(this).attr("alt");
    $("#" + id).fadeOut("slow");

});
这可能会奏效:

$("img", "#products").hover(function() {

    var id = $(this).attr("alt");
    $("#" + id).fadeIn("slow");

}, function() {

    var id = $(this).attr("alt");
    $("#" + id).fadeOut("slow");

});
可以在上看到以下内容

你可以像这样在鼠标上淡入淡出

var _current = "home"; // default state

$('#products img').mouseover(function (){

    // The one we want to show now
    var id= $(this).attr('alt');

    // We don't need to do anything if it's the same one that's already
    // there
    if (_current !== id){

        $('#' + _current).fadeOut(function(){
            // Fade in the new one after the old fades out
            $('#' + id).fadeIn();
            // Update state
            _current = id;
        });
    }
});
我还添加了一些东西,以确保在加载页面时只显示您希望首先显示的内容。我想应该是主播

将此添加到CSS中

.hidden{
    display:none;
}
把那个班的人放在其他班上

<div class="description hidden" id="services" >
 .. services.. 
</div>

<div class="description hidden" id="contact" >
 .. contact .. 
</div>

.. 服务。。
.. 联系。。
在上可以看到以下内容

你可以像这样在鼠标上淡入淡出

var _current = "home"; // default state

$('#products img').mouseover(function (){

    // The one we want to show now
    var id= $(this).attr('alt');

    // We don't need to do anything if it's the same one that's already
    // there
    if (_current !== id){

        $('#' + _current).fadeOut(function(){
            // Fade in the new one after the old fades out
            $('#' + id).fadeIn();
            // Update state
            _current = id;
        });
    }
});
我还添加了一些东西,以确保在加载页面时只显示您希望首先显示的内容。我想应该是主播

将此添加到CSS中

.hidden{
    display:none;
}
把那个班的人放在其他班上

<div class="description hidden" id="services" >
 .. services.. 
</div>

<div class="description hidden" id="contact" >
 .. contact .. 
</div>

.. 服务。。
.. 联系。。
另一个想法(没有Jquery):您可以使用CSS
opacity:x
属性(对于firefox)或
过滤器:alpha(opacity=x)
(对于IE)来更改元素的不透明度。淡入/淡出可以通过一个小的减速周期获得

另见:

另一个想法(没有Jquery):您可以使用CSS
opacity:x
属性(对于firefox)或
filter:alpha(opacity=x)
(对于IE)来更改元素的不透明度。淡入/淡出可以通过一个小的减速周期获得

另见:


我的假设是,您希望人们将鼠标悬停在图像按钮上,使相应的div淡入淡出。他们在该网站上所做的不会起作用,因为需要Javascript来实现淡入淡出的效果。JQuery使这变得简单。 我建议你试试这样的东西

<script type="text/javascript">
oldSelected = "home"
$(document).ready(function(){
  $("#products img").mouseover(function(){
    $(".description").stop(true, true);
    var newSelected = $(this).attr("alt");
    $("#" + oldSelected).fadeOut('normal',function(){
      $("#" + newSelected).fadeIn();
    });
    oldSelected = newSelected
  });
});
</script>

oldSelected=“home”
$(文档).ready(函数(){
$(“#产品img”).mouseover(函数(){
$(“.description”).stop(true,true);
var newSelected=$(this.attr(“alt”);
$(“#”+oldSelected).fadeOut('normal',function(){
$(“#”+newSelected).fadeIn();
});
oldSelected=newSelected
});
});
我已经测试了这个,它是有效的。您需要确保的一点是,div的css在开始时设置为不可见,除非您希望其中一个可见,在这种情况下,该div的id应该是您在函数开始时设置的oldSelected


享受吧

我的假设是,您希望人们将鼠标悬停在图像按钮上,使相应的div淡入淡出。他们在该网站上所做的不会起作用,因为需要Javascript来实现淡入淡出的效果。JQuery使这变得简单。 我建议你试试这样的东西

<script type="text/javascript">
oldSelected = "home"
$(document).ready(function(){
  $("#products img").mouseover(function(){
    $(".description").stop(true, true);
    var newSelected = $(this).attr("alt");
    $("#" + oldSelected).fadeOut('normal',function(){
      $("#" + newSelected).fadeIn();
    });
    oldSelected = newSelected
  });
});
</script>

oldSelected=“home”
$(文档).ready(函数(){
$(“#产品img”).mouseover(函数(){
$(“.description”).stop(true,true);
var newSelected=$(this.attr(“alt”);
$(“#”+oldSelected).fadeOut('normal',function(){
$(“#”+newSelected).fadeIn();
});
oldSelected=newSelected
});
});
我已经测试了这个,它是有效的。您需要确保的一点是,div的css在开始时设置为不可见,除非您希望其中一个可见,在这种情况下,该div的id应该是您在函数开始时设置的oldSelected


享受吧

希望你已经包括了提及css文件他们的?希望你已经包括提及css文件他们的?那应该是没有必要的。。。但你应该看看那个链接,它让我大开眼界很喜欢这个链接,但不幸的是,它与我的查询没有直接关系。基本上,我想根据鼠标悬停的菜单标题在div中淡入淡出。这应该不是必需的。。。但你应该看看那个链接,它让我大开眼界很喜欢这个链接,但不幸的是,它与我的查询没有直接关系。基本上,我想根据鼠标悬停的菜单标题在div中淡入。您好,我已经在我的页面中输入了函数,但无法使其工作-行中似乎有语法错误:哦,对不起。我忘了复制我正在测试和修复的版本。现在应该可以工作了。您好,我已经在我的页面中输入了函数,但无法使其工作-行中似乎有语法错误:哦,对不起。我忘了复制我正在测试和修复的版本。现在应该可以工作了。