首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

你如何在鼠标悬停时交换DIV?(jQuery的?)

在鼠标悬停时交换DIV,可以使用jQuery实现。以下是一个简单的示例代码:

代码语言:html
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>交换DIV示例</title>
   <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
   <style>
        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        .box {
            width: 100px;
            height: 100px;
            margin: 10px;
            background-color: #f0f0f0;
            border: 1px solid #ccc;
            text-align: center;
            line-height: 100px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="box" id="box1">Box 1</div>
        <div class="box" id="box2">Box 2</div>
    </div>
   <script>
        $("#box1").hover(function() {
            $("#box1").hide();
            $("#box2").show();
        }, function() {
            $("#box1").show();
            $("#box2").hide();
        });
    </script>
</body>
</html>

在这个示例中,我们使用了jQuery的hover()方法来监听鼠标悬停事件。当鼠标悬停在Box 1上时,Box 1会隐藏,Box 2会显示;当鼠标离开Box 1时,Box 1会重新显示,Box 2会隐藏。

需要注意的是,这个示例仅仅是一个简单的交互效果,实际应用中可能需要更复杂的交互效果和更好的用户体验。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

12分40秒

13分钟详解Linux上安装Vim插件—YouCompleteMe:文本编辑更强大和清爽

14分30秒

Percona pt-archiver重构版--大表数据归档工具

领券