请编辑 Javascript 以添加淡入/淡出效果

发布于 2024-12-06 14:23:51 字数 801 浏览 0 评论 0原文

是否可以在此 javascript 中添加淡入淡出效果?目前,它只是在第一个 div 悬停时将图像加载到另一个 div,但没有任何效果。提前致谢。

<script language="javascript" type="text/javascript"> 
    function changeDisplay(bgImageURL)
    {
            var displayDiv = document.getElementById("displayDiv");


        // draw popup image in the div
        displayDiv.innerHTML = 
            '<a class="popup1" href="#v"><img src="' + bgImageURL+ '" alt="" /></a>';
        // show the display in case it was hidden before
        displayDiv.style.visibility = "visible";
    }

    function hideDisplay()
    {
        var displayDiv = document.getElementById("displayDiv");

        // hide it when the mouse rolls off the thumbnail
        displayDiv.style.visibility = "hidden";
    }

    </script>

Is it possible to add a fade in fade out effect to this javascript? At the moment it just loads an image to another div upon hover of first div but with no effect. Thanks in advance.

<script language="javascript" type="text/javascript"> 
    function changeDisplay(bgImageURL)
    {
            var displayDiv = document.getElementById("displayDiv");


        // draw popup image in the div
        displayDiv.innerHTML = 
            '<a class="popup1" href="#v"><img src="' + bgImageURL+ '" alt="" /></a>';
        // show the display in case it was hidden before
        displayDiv.style.visibility = "visible";
    }

    function hideDisplay()
    {
        var displayDiv = document.getElementById("displayDiv");

        // hide it when the mouse rolls off the thumbnail
        displayDiv.style.visibility = "hidden";
    }

    </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

病女 2024-12-13 14:23:51

使用 jQuery

http://api.jquery.com/fadeIn/

<div id="fade"></div> <!-- make sure this is initially hidden -->

<script type="text/javascript">
  $('#fade').fadeIn('slow', function() {
    // When animation is complete, it runs this function
  });
</script>

fadeOuthttp://api.jquery.com/fadeOut/

Using jQuery

http://api.jquery.com/fadeIn/

<div id="fade"></div> <!-- make sure this is initially hidden -->

<script type="text/javascript">
  $('#fade').fadeIn('slow', function() {
    // When animation is complete, it runs this function
  });
</script>

fadeOut: http://api.jquery.com/fadeOut/

下壹個目標 2024-12-13 14:23:51

简单改变你现有的代码

include jquery plugin before your javascript code and change

显示功能

displayDiv.style.visibility = "visible"; to  displayDiv.fadeIn('slow');

隐藏功能

displayDiv.style.visibility = "visible"; to displayDiv.fadeOut();

simple change in your existing code

include jquery plugin before your javascript code and change

display function

displayDiv.style.visibility = "visible"; to  displayDiv.fadeIn('slow');

hide function

displayDiv.style.visibility = "visible"; to displayDiv.fadeOut();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文